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: