I have the following JSON structure:
[ {"id":"10", "class": "child-of-9"}, {"id":"11", "classd": "child-of-10"}];
how to iterate over it using jquery or javascript?
I have the following JSON structure:
how to iterate over it using jquery or javascript? |
||||
|
Taken from jQuery docs (http://docs.jquery.com/Utilities/jQuery.each):
|
|||||||||
|
note: the for-in method is cool for simple objects. Not very smart to use with DOM object. |
|||||||||||
|
Use foreach:
Will result in:
|
|||||||||||||||
|
This is your dataArray [{"id":28,"class":"Sweden"}, {"id":56,"class":"USA"}, {"id":89,"class":"England"}] Then,
|
|||
|
mootools example:
|
||||
|
You can use a mini library like objx - http://objx.googlecode.com/ You can write code like this:
There are more 'plugins' available to let you handle data like this, see http://code.google.com/p/objx-plugins/wiki/PluginLibrary |
|||
|
Another solution to navigate through JSON documents is JSONiq (implemented in the Zorba engine), where you can write something like:
You can run it on http://www.zorba-xquery.com/html/demo#AwsGMHmzDgRpkFpv8qdvMjWLvvE= |
||||
|
With nested objects, it can be retrieve as by recursive function:
where as events is json object. |
|||
|