Iterate in compact json structure using jquery
Is there easy way to iterate json structure like this ?
var xstri开发者_StackOverflow社区ng = [ {"test1",1} ,{"test2",2} ,{"test77","aa"} ] ;
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"
}
精彩评论