3 ways for jquery to traverse the JSON array _jquery

Source: Internet
Author: User

One, use each traversal

Copy Code code as follows:

$ (function () {

var tbody = "";
------------traverse the object. Use of each-------------
Object syntax JSON data format (when the server-side callback returns the object data format is JSON data format, you must ensure that the JSON format requirements, the callback object must use the Eval function to transform (otherwise it will not get object). This article does not provide a detailed description of the server-side callback data problem, we will directly customize the object.
var obj = [{"Name": "Navy", "Password": "123456"}];
$ ("#result"). HTML ("------------traversal object. Each use-------------");
alert (obj); is an OBJECT element
Use each to traverse the following
$.each (obj, function (n, value) {
Alert (n + ' + value ');
var trs = "";
TRS + + "<tr><td>" + value.name + "</td> <td>" + Value.password + "</td></tr>";
Tbody + = TRS;
});

$ ("#project"). Append (tbody);

});

Two, jquery traversal parsing JSON object 1:

Copy Code code as follows:

var json = [{dd: ' SB ', AA: ' Dongdong ', RE1:123},{CCCC: ' DD ', LK: ' 1QW '}];
for (Var i=0,l=json.length;i<l;i++) {
for (var key in Json[i]) {
Alert (key+ ': ' +json[i][key]);
}
}

Three, jquery traversal parse JSON object 2

There are the following JSON objects:

Copy Code code as follows:

var obj ={"name": "Feng Juan", "Password": "123456″," "Department": "Technical department", "Sex": "female", "old": 30};

Traversal method:
Copy Code code as follows:

For (var p in obj) {
str = str+obj[p]+ ', ';
return str;
}

PS: Here again for you to recommend a few more practical JSON online tools for your reference to use:

Online JSON code inspection, inspection, landscaping, formatting tools:
Http://tools.jb51.net/code/json

JSON Online formatting tool:
Http://tools.jb51.net/code/jsonformat

Online Xml/json Mutual Conversion tool:
Http://tools.jb51.net/code/xmljson

JSON code online Format/beautify/compress/edit/Convert tools:
Http://tools.jb51.net/code/jsoncodeformat

Online JSON compression/escape tool:

Http://tools.jb51.net/code/json_yasuo_trans

C Language Style/html/css/json code formatting landscaping Tools:
Http://tools.jb51.net/code/ccode_html_css_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.