JavaScript loops to read the code _json of JSON data

Source: Internet
Author: User
The JSON format string returned to the client by the server backend:
var str = ' [{uname ']: "Wang Qiang", "Day": "2010/06/17"},{"uname": "Wang Haiyun", "Day": "2010/06/11"}] ';

We convert it to a JSON object: Var jsonlist=eval ("+str+"); If you use a breakpoint to track the Jsonlist object, you will find that he is 2, that is, jsonlist.length=2. Each of its entries is a separate JSON object. Take a look at the picture below:


Assuming we do not know the two key values of "uname" and "Day", we begin the loop operation on Jsonlist.
Copy Code code as follows:

for (Var i=0;i<jsonlist.length;i++) {

for (var key in Jsonlist[i]) {
Alert ("Key:" +key+ ", Value:" +jsonlist[i][key]);
}
}

So we can easily get the key and value values I need.

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.