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

143
Views
Cómo manejar valores verdaderos/falsos en objetos JSON

Tengo un problema donde mi objeto JSON tiene True en lugar de true y False en lugar de false. Eso está causando problemas cuando lo analizo en JSON. ¿Cómo resuelvo este problema? En el siguiente script, obj2 no funciona, ya que tengo el booleano True pero no la cadena.

 <!DOCTYPE html> <html> <body> <h2>Creating an Object from a JSON String</h2> <p id="demo1"></p> <p id="demo2"></p> <script> const txt1 = '{"device_state": {"device_name": "iPhone", "is_phone": true, "is_VOX": false}}' const obj1 = JSON.parse(txt1); document.getElementById("demo1").innerHTML = obj1.device_state.device_name const txt2 = '{"device_state": {"device_name": "iPhone", "is_phone": True, "is_VOX": false}}' const obj2 = JSON.parse(txt2); document.getElementById("demo2").innerHTML = obj2.device_state.device_name </script> </body> </html>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

No puedo ver qué te impide asignar "is_phone": cierto, pero si por alguna razón te resulta difícil, puedes cambiar el código a este

 var txt2 = '{"device_state": {"device_name": "iPhone", "is_phone": True, "is_VOX": false}}'; txt2=txt2.replaceAll("True","true").replaceAll("False","false"); const obj2 = JSON.parse(txt2);
about 4 years ago · Juan Pablo Isaza 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!