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

119
Views
Cadena a json sin matriz

Tengo una cadena que se parece a la siguiente:

 { "results": [ { "address_components": [ { "long_name": "Ireland", "short_name": "Ireland", "types": [ "establishment", "natural_feature" ] } ], "formatted_address": "Ireland", "geometry": { "bounds": { "northeast": { "lat": 55.38294149999999, "lng": -5.431909999999999 }, "southwest": { "lat": 51.4475448, "lng": -10.4800237 } }], "status" : "OK" }

Quiero convertir esto en un json que pueda atravesar fácilmente. Sin embargo, cuando llamo a JSON.parse() en esta cadena, obtengo una matriz json que es difícil de atravesar. Quiero poder extraer la latitud y longitud del noreste sin tener que recorrer toda la matriz.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

 var json = `{ "results": [ { "address_components": [ { "long_name": "Ireland", "short_name": "Ireland", "types": [ "establishment", "natural_feature" ] } ], "formatted_address": "Ireland", "geometry": { "bounds": { "northeast": { "lat": 55.38294149999999, "lng": -5.431909999999999 }, "southwest": { "lat": 51.4475448, "lng": -10.4800237 } } } } ], "status" : "OK" }`; var data = JSON.parse(json); var bounds = data.results[0].geometry.bounds; var bound = bounds.northeast || bounds.southwest; console.log(bound.lat, bound.lng);

Si sabe que el noreste siempre es una opción, puede simplificar esto a:

 console.log(data.results[0].geometry.bounds.northeast);

Eso te dará tu lat y lng.

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!