Jquery traversal of json object sets _ jquery

Source: Internet
Author: User
This article mainly introduces three situations: jquery traversing json object sets, jQuery traversing JSON objects, and jquery traversing and reading objects in json strings, if you are interested, you can refer to the case study in this article to introduce three situations of jquery traversing json objects for your reference. The details are as follows:

First case: Common examples of jquery traversing json object sets

Jsp

$. Ajax ({url: "$ {applicationScope. rootpath} common/getContractPage.html? UserConId =$ {userConId} ", type:" post ", dataType:" json ", data :{}, success: function (jsonText) {if (jsonText) {var status = jsonText. status; var msg = jsonText. msg; if (status = '000000') {// alert (msg) When an exception occurs;} else {$. each (jsonText, function (I, item) {var pngPath = item [0]; var pngName = item [1] ;}}});

JsonText format:

{"Status": "200", "msg": [{"id": "1", "name": "n1" },{ "id ": "2", "name": "n2"}]} {"status": "500", "msg": "exception information "}

In java:

List pngFileList = new ArrayList (); // if (null! = PngFileList & pngFileList. size ()> 0) {JSONArray pngFileArray = JSONArray. fromObject (pngFileList);} if (null! = PngFileArray) {this. setTextAjax (pngFileArray. toString (); // The format of the exception // this. setTextAjax ("{\" status \ ": \" 500 \ ", \" msg \ ": \" "+ errormsg + "\"}"); // No record/*** ajax returns html, including the json form ** @ param responseContent */public void setTextAjax (String responseContent) {try {HttpServletResponse response = getHttpResponse (); response. setContentType ("text/html"); response. setCharacterEncoding ("UTF-8"); response. setHeader ("Pragma", "No-cache"); response. setHeader ("Content-Type", "text/html"); response. setHeader ("Cache-Control", "no-cache"); response. setDateHeader ("Expires", 0); PrintWriter out = response. getWriter (); out. print (responseContent); out. flush (); out. close ();} catch (IOException e) {e. printStackTrace ();} // ajaxResponse = new StringBufferInputStream (responseContent );}

Case 2:JQuery traverses JSON objects

Without saying anything else, paste the Code directly:

Related Article

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.