views:

42

answers:

1

My JSON looks like this:

{
"[email protected]":"Person1",
"[email protected]":"Person65",
"[email protected]":"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!

+3  A: 

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.

Tatu Ulmanen
awesome! thanks!!
Obay