Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

98
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda