Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

261
Views
Cómo convertir un valor de cadena en un objeto en Javascript con un comando similar a eval en Python

En Python, stringValue se proporcionó como una variable de cadena:

 stringValue = '{"DATA":{"VERSION":1.1, "STATE":True, "STATUS":"ONLINE"}}'

Puedo seguir adelante y "convertirlo" o "lanzarlo" como diccionario de Python usando la función integrada eval :

 result = eval(stringValue)

¿Hay alguna manera de hacer lo mismo en javascript si nos dieran var stringValue como:

 var stringValue = '{"DATA":{"VERSION":1.1, "STATE":true, "STATUS":"ONLINE"}}'
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

usar evaluación

Con una advertencia ... deberá agregar ( y ) a la cadena

 // this is the ORIGINAL value of the string in the question!!! var stringValue = "{'DATA':{'VERSION':1.1, 'STATE':true, 'STATUS':'ONLINE'}}"; var result = eval(`(${stringValue})`); console.log(result)

Ahora que usted cambió el código en la pregunta después de que publiqué la respuesta original ... es decir, intercambió ' y " - ahora PUEDE usar JSON.parse como comentario sugerido

 var stringValue = '{"DATA":{"VERSION":1.1, "STATE":true, "STATUS":"ONLINE"}}'; var result = JSON.parse(stringValue); console.log(result);

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!