开发者

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"
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜