I am playing with the 1.4.1 jquery.parseJSON method and looks like it would be a good fit for my project which is iterating over a JSON string that is loaded from C#. However, the JSON that gets loaded is an entity object and they have generic collections inside of them and thus creates the same name in the JSON string. For example:
This works because theres only item with a name all to itself:
var obj = jQuery.parseJSON('{\"ItemID\":1014470}');
alert(obj.ItemID);
This works but only gets the last item in the JSON string:
var obj = jQuery.parseJSON('{\"ItemID\":1014470,\"ItemID\":134564879898798}');
alert(obj.ItemID);
So I thought separating the JSON string as follows would solve it:
var obj = jQuery.parseJSON('{\"ItemID\":1014470},{\"ItemID\":134564879898798}');
Which of course does nothing
I was thinking that you could do something like this:
jQuery.each(obj, function(){
// get each ItemID ???
});
Is there a better way to do something like this?
Currently we use these ugly javascript arrays with lots and lots of looping methods, I was hoping jQuery could provide a cleaner way of iterating over a JSON string.
To repeat items, you use an array. Either an array of objects:
or an object that has an array as member:
The first one you can loop using:
The second you can loop using: