开发者

How to decode JSON (varying number of elements, varying keys) using Jquery

My JSON looks like this:

{
"person1@email.com":"Person开发者_JAVA百科1",
"person65@email.com":"Person65",
"person24@email.com":"Person24"
}

It's returned in various number of elements, and various keys. How do I traverse the data if my code is like this:

$.post("includes/ajax.php", {
    group_id : $('#group').val() 
}, function(data) {
    //how do i traverse data here?
}, "json");

Any help will be appreciated :)

Thanks!


jQuery already parses the JSON data to an object so you can traverse it like this for example:

for(var address in data) {
    var name = data[address];

    alert(name + " " + address);
}

Your data structure is a bit sub-optimal though, you should use multidimensional arrays instead of the emails as key, but that's irrelevant.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜