Recently, Jquery was used in our work to parse json strings. There are many examples of jquery parsing json single objects on the Internet, but there are not many examples of jquery parsing json arrays, here is a simple example to share with you. I have a limited level and hope you will criticize and advise me.
Json string of A json object array:
var str=[{"Price":12,"Name":"aaa","Age",22},{"Price":24,"Name":"bbb","Age",33}];
On the front-end, use the parseJSON method of jquery for parsing and use the jquery foreach Method for parsing. The Code is as follows:
var jsonarray= $.parseJSON(str);alert(jsonarray);$.each(jsonarray, function (i, n){ alert(n.Price);}
For jquery of different versions, the string format of the json object array to be parsed is also different (I used two different versions of jquery and I encountered this problem ), if the above Code cannot be parsed, use the eval function to wrap it. The Code is as follows:
var jsonarray= $.parseJSON(str);$.each(eval("(" + jsonarray+ ")"), function (i, n) { alert(n.Price);}
When parsing the json object array string, you can also use alert to pop up $. after parseJSON (str) is parsed, if an object is displayed in the pop-up dialog box, the parsing is successful. You can use the object. the property name obtains the value of the corresponding property. If the pop-up is not an object, use eval () to wrap it to form an object, and then obtain the value of the corresponding property.
The above is my little experience in using jquery to parse arrays of json objects. I am looking forward to your comments.