
本文实例采用案例分析的方法介绍了jquery遍历json对象的三种情况,供大家参考,具体内容如下
第一个案例:jquery 遍历json对象集合 常用示例
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 == 500){
//有异常的信息时
alert(msg);
}else{
$.each(jsonText,function(i,item){
var pngPath = item[0];
var pngName = item[1];
});
}
}
}
});
jsonText的格式:
{“status”:”200″,”msg”:[{“id”:”1″,”name”:”n1″},{“id”:”2″,”name”:”n2″}]}
{“status”:”500″,”msg”:”异常信息”}
java中:
List pngFileList = new ArrayList();//某对象集合
if(null != pngFileList