Home > Web Front-end > JS Tutorial > 3 ways to traverse json arrays with JQuery_jquery

3 ways to traverse json arrays with JQuery_jquery

WBOY
Release: 2016-05-16 16:32:00
Original
1577 people have browsed it

1. Use each to traverse

Copy code The code is as follows:

$(function () {

var tbody = "";
//------------Usage of traversing object .each-------------
//Object syntax JSON data format (when the object data format returned by the server callback is json data format, the format requirements of JSON must be ensured, and the callback object must be converted using the eval function (otherwise, the Object will not be obtained). This article will not go into details Introducing the data issue of server-side callback, we will customize the object directly)
             var obj = [{ "name": "Xiang Haijun", "password": "123456"}];
           $("#result").html("------------遍历对象 .each的使用-------------");
             alert(obj); //It is an object element
​​​​​​ //Use each to traverse below
$.each(obj, function (n, value) {
alert(n ' ' value);
            var trs = "";
                trs = "" value.name " " value.password "";
              tbody = trs;
            });

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

});

2. jquery traversal and parsing json object 1:

Copy code The code is as follows:

var json = [{dd:'SB',AA:'东东',re1:123},{cccc:'dd',lk:'1qw'}];
for(var i=0,l=json.length;i for(var key in json[i]){
alert(key ':' json[i][key]);
}
}

3. jquery traversal and parsing json object 2

has the following json object:

Copy code The code is as follows:

var obj ={"name":"Feng Juan","password":"123456","department":"Technical Department","sex":"Female","old":30};

Traversal method:
Copy code The code is as follows:

for(var p in obj){
str = str obj[p] ',';
Return str;
}
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template