前端之家收集整理的这篇文章主要介绍了
jquery遍历json对象集合详解,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_403_0@本文实例采用案例分析的方法介绍了jquery遍历json对象的三种情况,供大家参考,具体内容如下
@H_
4030@第一个案例:<span style="color: #800000">jquery 遍历json对象集合 常用示例
@H403_0@jsp中
<div class="jb51code">
<pre class="brush:js;">
$.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 == '500'){
//有异常的信息时
alert(msg);
}else{
$.each(jsonText,function(i,item){
var pngPath = item[0];
var pngName = item[1];
});
}
}
}
});
0) {
JSONArray pngFileArray =JSONArray.fromObject(pngFileList);
}
if(null != pngFileArray){
this.setTextAjax(pngFileArray.toString());
//异常的格式
//this.setTextAjax("{\"status\":\"500\",\"msg\":\""+errormsg+"\"}");//没有记录
/**
- ajax返回html,包括json形式
-
- @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);
}