I agree with some comments that you can just keep using XML. If you want to convert to JSON, you must use the For In loop in javascript to scroll it in exactly the same way you would use an object in javascript.
Your data in JSON:
{"itemnumbers": { "item": {"itemno": 123, "desc": "Desc about 123"} } { "item": {"itemno": 456, "desc": "Desc about 456"} } }
Looping around your data where the data is a JSON object above:
for (item in data.itemnumbers) { //do something with item data console.log(data.itemnumbers[item].itemno); console.log(data.itemnumbers[item].desc); }
To store an object in localStorage, you must convert it to a string format that you can return back as an object. You can use JSON.stringify () to make the object a string and JSON.parse () to pull it back:
//saving object to localStorage localStorage['my_data'] = JSON.stringify(data); //fetching object from localStorage data = JSON.parse(localStorage['my_data']);
Beware, because these methods are not supported in IE7 and below, so you need to find a compatible parsing library with them. Here's a post that might help with compatibility:
Safely turning a JSON string into an object
Ben l source share