Home  >  Article  >  Web Front-end  >  JQuery parses multi-dimensional Json data format_jquery

JQuery parses multi-dimensional Json data format_jquery

WBOY
WBOYOriginal
2016-05-16 18:42:341041browse

This requires the use of JQuery, ASHX and Json to cooperate. An article has multiple comments, each of ten comments per page. Every time the user clicks on the next page, the next page will be automatically grabbed. This process can be carried out safely without refreshing.
Json format is actually similar to table format. In network transmission, it saves traffic than XML, and it is better integrated with JS and is easier to parse. A sample Json format is as follows:

Copy code The code is as follows:

{"Products":[
{"orderid":"11077","customerid":"RATTC"},
{"orderid":"11078","customerid":"RATT"}
],
" Img":[{"id":"12345","url"
:"image/1.jpg"}
]}

We can think of Products and Img as The name of a table. In the Products table, orderid and customerid are both fields of Products. 11077 and RATTC can be understood as the values ​​of the corresponding fields. The same goes for the Img part. Therefore, there are two records for Products above, while there is only one record for Img.
So how do we parse out the corresponding tables, fields and values ​​in JQuery?
In JQuery we can use:
var Products= Json.Products;
to filter the Products table. Next, we loop through Products to read the values:
Copy the code The code is as follows:

$.each(Products, function(i, n) {
str = "

" n.orderid "ID" n.customerid "

";
});

$.each(Products, function(i, n) {} Products here is the table in our target Json data. i represents the order of records, starting from 0 (0 represents the first stroke, 1 represents the second stroke...), and n represents the value of the corresponding field. The reading of Img is also similar~~
Please correct me if there is anything inappropriate, thank you!
Statement:
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