Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

184
Visualizações
how to convert to json string

This could be a basic question but , i'm stuck with this for some time.

i have a data

{pid: 'WEB506', session: 'WEB506_09092021_M1_S1.csv'}

how to convert this to

{
        "pid":"WEB506",
        "session":"WEB506_09092021_M1_S2.csv"
        };

regards. i used JSON.stringify and i got it as

{"pid":"WEB506","session":"WEB506_09092021_M1_S1.csv"}

but when i pass this to ajax data to call an api , the value entering req.body is

{ '{"pid":"WEB506","session":"WEB506_09092021_M1_S1.csv"}': '' }

This is my ajax call

function graphApi(){
    
     const apiValue = JSON.parse(localStorage.getItem('user'));
     
   console.log(apiValue,"apiValue");
      const f = JSON.stringify(apiValue);
      console.log(f,"ffff")
       $.ajax({
        type: "POST",
        data:  f,   
       
        url: "http://localhost:5000/File",
        success: function (data) { 
        console.log(data,"graph api");
         }

I really don't know what is happening.

regards

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

JSON.stringify()

should give you serialized string for your data.

I think the issue here is you are passing the string as the payload to the AJAX call whereas you should use the data(i.e the object) directly in req. body. See if this helps

about 4 years ago · Juan Pablo Isaza Relatório

0

JSON.stringify() is used to stringify the objects

about 4 years ago · Juan Pablo Isaza Relatório

0

This is your Object Right

   const object = {
                  "pid":"WEB506",
                  "session":"WEB506_09092021_M1_S2.csv"
                };

Now Pass this object in the below method

const jsonObject = JSON.parse(object);
console.log(jsonObject)

Now you can dig out your PID or SESSIONS with

const pid = jsonObject.pid
const session = jsonObject.session
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda