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 
scoob
  • 367
  • 2
  • 14
  • Ya tell us what coords is. Im guessing thats the json object? – Kyle Weller Nov 09 '13 at 08:21
  • @arkonautom added the results – scoob Nov 09 '13 at 08:23
  • Have a look at the MDN documentation about `for...in` (especially the examples): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in. – Felix Kling Nov 09 '13 at 08:24
  • possible duplicate of [How do I enumerate the properties of a javascript object?](http://stackoverflow.com/questions/85992/how-do-i-enumerate-the-properties-of-a-javascript-object) – Felix Kling Nov 09 '13 at 08:25
  • Note: Your problem has nothing to do with JSON. *How* you got the data is irrelevant to the problem (which is how to iterate over object properties). – Felix Kling Nov 09 '13 at 08:36

1 Answers1

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]);
                  }
            }
rajesh kakawat
  • 10,826
  • 1
  • 21
  • 40