[英]Having trouble walking JSON structure
I have a json structure that looks like this: 我有一个看起来像这样的json结构:
[
{
"coordinates": [
75.71027043,
26.88661823
]
},
{
"coordinates": [
75.71027043,
26.88661823
]
}
]
I'm trying to access the coordinates so that I can feed them into a google maps API latlng. 我正在尝试访问坐标,以便可以将其输入到Google Maps API latlng中。
function loadTweets(results) {
var tweetStructure = $.parseJSON(results);
console.log(tweetStructure);
for (a in tweetStructure){
console.log(a);
for (coords in a){
console.log(coords);
}
}
var myLatlng = new google.maps.LatLng(coords[0],coords[1]);
Whenever I try and walk the structure with this code I end up with the keys instead of the values (I think). 每当我尝试使用此代码遍历结构时,我最终都会使用键而不是值(我认为)。 Can anyone point out what I'm doing incorrectly? 谁能指出我做错了什么?
Here's what I'm getting back: 这是我回来的东西:
[Object, Object, Object, Object, Object, Object]
0: Object
coordinates: Array[2]
__proto__: Object
1: Object
2: Object
3: Object
4: Object
5: Object
length: 6
__proto__: Array[0]
0
0
1
0
try something like this 尝试这样的事情
var tweetStructure = $.parseJSON(results);
for (a in tweetStructure){
var co_arr = tweetStructure[a];
for (coords in co_arr.coordinates){
console.log(co_arr.coordinates[coords]);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.