JS convenient JSON array method
Get the value of a key inside the Jason object by using the method:
1, Object ["Key"].
2, object. Key.
This article mainly introduces the 3 methods of jquery traversal JSON array, this article gives the method of using each and for traversal JSON, where for is divided into two forms, the need for friends can refer to the following
$(function () { varTbody = ""; //------------traverse the object. Each use------------- //object Syntax JSON data format (when the server-side callback Object Data format is JSON data format, must ensure that the JSON format requirements, the callback object must use the Eval function to convert (otherwise will not get object). This article does not give a detailed description of the server-side callback data issues, we will directly customize the object) varobj = [{"Name": "Item Navy", "Password": "123456"}]; $("#result"). HTML ("------------traversal object. Each use-------------"); alert (obj); //It's an object element . //The following uses each to traverse$.each (obj,function(n, value) {alert (n+ ' +value); varTRS = ""; TRS+ = "<tr><td>" + value.name + "</td> <td>" + Value.password + "</td></tr>"; Tbody+=TRS; }); $("#project"). Append (tbody); });
Ii. jquery Traversal parsing JSON object 1:
var json = [{dd: ' SB ', AA: ' Dongdong ', RE1:123},{CCCC: ' DD ', LK: ' 1qw 'for (var i=0,l= json.length;i<l;i++) { for (var in json[i]) { alert (key+ ': ' +Json[i][key]); } }
Iii. jquery Traversal parsing JSON object 2
The following JSON objects are available:
var obj ={"name": "Feng Juan", "Password": "123456″," "Department": "Technical department", "Sex": "female", "old": 30};
Traversal method:
for (var in obj) { = str+obj[p]+ ', '; return str;}
JS convenient JSON array method