Home > Web Front-end > JS Tutorial > javascript code for looping to read JSON data_json

javascript code for looping to read JSON data_json

WBOY
Release: 2016-05-16 18:22:55
Original
1011 people have browsed it

The server backend returns the JSON format string to the client:
var str = '[{"uname":"Wang Qiang","day":"2010/06/17"},{"uname":"Wang Haiyun" ,"day":"2010/06/11"}]';

We convert it into a JSON object: var jsonList=eval("(" str ")"); At this time, if you use Click to trace and view this jsonList object. In fact, you will find that its length is 2, that is, jsonList.length=2. Each of its items is a separate JSON object. Please look at the picture below:

javascript code for looping to read JSON data_json
At this time, assuming that we do not know the key values ​​​​of "uname" and "day", we start to perform loop operations on jsonList.

Copy code The code is as follows:

for(var i=0;i
for(var key in jsonList[i]){
alert("key:" key ",value:" jsonList[i][key]);
}
 }

 This way we can easily get the key and value values ​​I need.
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