Analysis of jQuery's json Traversal method _ jquery-js tutorial

Source: Internet
Author: User
This article mainly introduces jQuery's method of traversing json, and analyzes jQuery's techniques for Traversing json data in the form of examples, for more information about jQuery's json Traversal method, see the example in this article. We will share this with you for your reference. The details are as follows:

The Code is as follows:

Var obj = {"status": 1, "bkmsg": "\ u6210 \ u529f", "bkdata": ["\ u5415 \ u5c1a \ u5fd7", "1387580400 ", "\ u6dfb \ u52a0 \ u8bb0 \ u5f55"]} {"status": 1, "bkmsg": "\ u6210 \ u529f", "bkdata ": ["\ u5415 \ u5c1a \ u5fd7", "1387580400", "\ u6dfb \ u52a0 \ u8bb0 \ u5f55"]}, {"status": 1, "bkmsg ": "\ u6210 \ u529f", "bkdata": ["\ u5415 \ u5c1a \ u5fd7", "1387580400", "\ u4ec0 \ u4e48 \ u4e5f \ u6ca1 \ u6709"]}

Ajax request:

$. Ajax ({url: '/path/to/file', type: 'get', dataType: 'json', data: {param1: 'value1'}, success: function (obj) {// traverse obj }})

The returned content is in the success function. All traversal operations are performed here:

For Loop:

Var obj = {"status": 1, "bkmsg": "\ u6210 \ u529f", "bkdata": ["\ u5415 \ u5c1a \ u5fd7", "1387580400 ", "\ u6dfb \ u52a0 \ u8bb0 \ u5f55"]} // console. log (obj. length); if (obj. status = 1) {for (var I = 0; I <obj. bkdata. length; I ++) {console. log (obj. bkdata [I]) ;};} else {alert ("data error ~ ");};

For in loop:

// For in loop for (x in obj. bkdata) {// x indicates a subscript to specify a variable. The specified variable can be an array element or an object attribute. Console. log (obj. bkdata [x]);} // element each method if (obj. status = 1) {$ (obj. bkdata ). each (function (index, item) {// index indicates the subscript // item indicates the content of the corresponding element. // this indicates each element object // console. log (obj. bkdata [index]); console. log (item); // console. log ($ (this) ;}) ;}else {alert ("data error ~ ") ;}; // Jquery each method $. each (obj. bkdata, function (index, item) {console. log (item );});

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.