How jquery iterates through JSON

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.