jQuery解析json格式数据示例
本文实例讲述了jQuery解析json格式数据。分享给大家供大家参考,具体如下:
vararr1=["one","two","three","four","five"];
$.each(arr1,function(){
alert(this);
});
输出:
one two three four five
vararr2=[[1,2,3],[4,5,6],[7,8,9]]
$.each(arr2,function(i,item){
alert(item[0]);
});
输出:
1 4 7
varobj={one:1,two:2,three:3,four:4,five:5};
$.each(obj,function(key,val){
alert(obj[key]);
});
输出:
1 2 3 4 5
//json格式
varparam=[{'subJobClass':'com.sample.quartz.MyJob','subJobMethod':'hello','taskParam':[{'username':'张三'},{'age':'28'},{'tel':'15818821129'}]}];
//设置参数值
if(param.length>0){
alert(param[0].subJobClass);
alert(param[0].subJobMethod);
vartaskParam=param[0].taskParam;
//遍历任务参数数组
jQuery.each(taskParam,function(i,item){
//解析单个任务参数
jQuery.each(item,function(key){
alert(key);//key
alert(item[key]);//value
});
});
}
感兴趣的朋友可以使用在线HTML/CSS/JavaScript代码运行工具:http://tools.jb51.net/code/HtmlJsRun测试上述代码运行效果。
PS:关于json操作,这里再为大家推荐几款比较实用的json在线工具供大家参考使用:
在线
JSON在线格式化工具:
http://tools.jb51.net/code/jsonformat
在线XML/