var obj = {"Status": 1, "bkmsg": "\u6210\u529f", "Bkdata": ["\u5415\u5c1a\u5fd7", "1387580400", "\u6dfb\u52a0\u8bb0\ U5f55 "]}{" Status: 1, "bkmsg": "\u6210\u529f", "Bkdata": ["\u5415\u5c1a\u5fd7", "1387580400", "\u6dfb\u52a0\u8bb0\ U5f55 "]},{" Status: 1, "bkmsg": "\u6210\u529f", "Bkdata": ["\u5415\u5c1a\u5fd7", "1387580400", "\u4ec0\u4e48\u4e5f\ u6ca1\u6709 "]}
//===================================================================
Ajax requests:
$.ajax ({ URL: '/path/to/file ', type: ' GET ', dataType: ' JSON ', data: {param1: ' value1 '}, success : function (obj) { //traverse obj } })
The returned content is inside the success function, where all the traversal operations are done:
For loop:
var obj = { "status": 1, "bkmsg": "\u6210\u529f", "Bkdata": ["\u5415\u5c1a\u5fd7", "1387580400", "\u6dfb\ U52a0\u8bb0\u5f55 "] } //Console.log (obj.length); if (obj.status = = 1) {for (var i = 0; i < obj.bkdata.length; i++) { console.log (obj.bkdata[i]); }; }else{ alert ("Incorrect data ~");
For In loop:
The For In loop for (x in Obj.bkdata) { //x is the subscript that specifies the variable, which can be an array element or an object's property. Console.log (obj.bkdata[x]); }
Element each method
if (obj.status = = 1) { $ (obj.bkdata). each (function (index,item) {//index = subscript //item refers to the contents of the corresponding element // This refers to each element of the object //console.log (Obj.bkdata[index]); Console.log (item); Console.log ($ (this)); }); else{ alert ("Incorrect data ~");
jquery each method
$.each (Obj.bkdata, function (index,item) { console.log (item); });
How jquery iterates through JSON