Saturday 15 January 2011

jquery - iterating over json with numeric key using $.each -


I use an AJAX call to pass a Jason from the server to the client. Json has the following structure:

  var data = {"2001": {"name": "tom", "age": 33, "pos": "mk"}, 3602 ": {" name ":" cindy "," age ": 56," pos ":" cs "}," 1060 ": {" name ":" mike "," age ": 23," pos ": "MG"}}   

I have $ N $ to access "name" and "pause" in nested object. For some reason I can not go deep into it alone through the first stage (i.e. "2001", "3602", ...) Syntax I only warn numeric keys.

  $ Each (data, function (id, object) {warning (data [key]););   

When I execute this code then nothing happens. As such, when I try to run the following code to use all the names, nothing happens:

  $ Each (data, function (id, object) {$ .each (object, function (key, value) {warning (data [key] .name);});});   

I know that Javascript does not like numerical keys, but I have noticed that others use data in numeric keys using data ["2001"], so It is possible that any help made by a Jason structured this way is greatly appreciated.

its simple ....

  $ .EEC , Function (id, object) {warning (data [id] .name); alerts (data [id] .pos);});    

No comments:

Post a Comment