views:

238

answers:

1

Hey, Is there easy way to iterate json structure like this ?

var xstring = [ {"test1",1} ,{"test2",2} ,{"test77","aa"} ] ;
+3  A: 

Samir Talwar is right, the data inside the curly brackets is a dictionary so instead you'll have something like this.

var xstring = [ {"test1": 1}, {"tests2": 2}, {"test3": "aa"} ];

But then, it doesn't really make much sense to have different dictionaries, with only one key, maybe what you are looking for is just a dictionary (object), like this.

var xstring = { "test1": 1, "test2": 2, "test3": "aa" };

So xstring is a dictionary/object type, there's not really an iterator object in javascript, but you could just go through the items, using a for loop.

for(var property in xstring){
  xstring[property]; // Here are your values: 1, 2, "aa"
}
UberNeet