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