0

I have a json structure that looks like this:

[
    {
        "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.

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 
4

1 回答 1

0

尝试这样的事情

             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]);
                  }
            }
于 2013-11-09T08:27:34.553 回答