简体   繁体   English

从js中的嵌套json检索数据

[英]Retrieve data from nested json in js

I have the json response from google elevation service as: 我有来自谷歌海拔服务的json响应为:

{
   "results" : [
      {
         "elevation" : 1340.76708984375,
         "location" : {
            "lat" : 27.717098,
            "lng" : 85.346625
         },
         "resolution" : 152.7032318115234
      },
      {
         "elevation" : 1336.588745117188,
         "location" : {
            "lat" : 27.712471009522,
            "lng" : 85.34499693093947
         },
         "resolution" : 152.7032318115234
      },
      {
         "elevation" : 1331.822631835938,
         "location" : {
            "lat" : 27.707844,
            "lng" : 85.343369
         },
         "resolution" : 152.7032318115234
      }
   ],
   "status" : "OK"
}

I am able to retrieve elevation and resolution using (here lets take value of first array 0) 我可以使用检索海拔高度和分辨率(此处取第一个数组0的值)

results[0].elevation

but I am not being able to retrieve lat and lng value using 但是我无法使用以下方法检索经度和经度值

results[0].location.lat

which I think is correct approach. 我认为这是正确的方法。

Can anyone tell me where I am wrong and how can I retrieve data of lat and lng. 谁能告诉我哪里错了,我该如何检索经纬度的数据。

Using console.log(results[0].location) 使用console.log(results[0].location)

for debugging I get response as 用于调试我得到响应

Object { k: 27.73574, B: 85.33218 }

then I was able to get lat and lng value using 然后我就可以使用

results[0].location.k results[0].location.b

Don't know how was this possible but it works. 不知道这怎么可能,但是可行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM