Home >
Article > Web Front-end > Implementation code for traversing two Json data structures through Jquery_jquery
Implementation code for traversing two Json data structures through Jquery_jquery
WBOYOriginal
2016-05-16 18:11:27964browse
In ajax interaction, the data types we return from the server include xml, html, script, json, jsonp, and text. This article uses json as an example to describe how to use jquery to traverse the two data structures of json in the foreground: "name/ A collection of "value" pairs, an ordered list of values, and an ordered list of values containing a collection of "name/value" pairs. On the server side, we use Json.NET to serialize arraylist, hashTable, list<> and other data structures. Before we start, we need to download Json.net. After the download is completed, add a reference to the website and open the downloaded folder. If it is .net2.0 or above, use Newtonsoft.Json in the DoNet folder. dll, if it is version 2.0, use Newtonsoft.Json.dll under the DotNet20 file, and then import its namespace using Newtonsoft.Json on the page you are using; After the preparations are completed, start the demonstration below, first add the webService file naming to ProductService.asmx, and then uncomment [System.Web.Script.Services.ScriptService]. 1. Traverse the collection of "name/value" pairs ProductService.asmx Add the getProductInfoToJson method
$.ajax({ type: "POST", url: "ProductService.asmx/GetReceiverAddressInfo", data: "{}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { var resultCollection = jQuery.parseJSON(msg.d); $.each(resultCollection, function (index, item) { var AddressInfo = [ ' ' ].join(''); }); } });
在1.41中,jquery添加了 jQuery.parseJSON( json ) 的方法,该方法的定义是Takes a well-formed JSON string and returns the resulting JavaScript object. 就是接受一个格式良好的JSON字符串,返回一个Javascript对象。 这大大方便了我们在前台对服务器端生成的Json字符串的处理. 好了,关于Jquery遍历Json两种数据结构的介绍就到这里
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