JS convenient JSON array method

Source: Internet
Author: User

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

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.