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

94
Visualizações
After posting JSON with jQuery, convert the string back into a JSON

So I have some code that posts this JSON:

post = {
    period: "1",
    data: {1: "Here"}
}

And it is posted with this code:

$.ajax({
    url: 'http://127.0.0.1:5000/',
    data: post,
    type: 'POST'
})

When I execute this code, my server receives this string: "period=1&data%5B3%5D=Here"

Is there a way to convert this string back into a JSON?

I have tried JSON.parse() but that obviously did not work.

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

0

It was never JSON, you can send it as JSON by using JSON.stringify and then use JSON.parse to get it back as an object on the server.

$.ajax({
    url: 'http://127.0.0.1:5000/',
    data: JSON.stringify(post),
    contentType: 'application/json',
    type: 'POST'
})
about 4 years ago · Juan Pablo Isaza Relatório

0

You can parse the string with the URLSearchParams constructor, then use Object.fromEntries to convert it to an object:

const obj = Object.fromEntries(new URLSearchParams("period=1&data%5B3%5D=Here"));
console.log(obj)

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