jQuery解析json格式数据示例

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

jQuery解析json格式数据示例

gundumw100   2020-05-16 我要评论

本文实例讲述了jQuery解析json格式数据。分享给大家供大家参考,具体如下:

var arr1 = [ "one", "two", "three", "four", "five" ];
$.each(arr1, function(){
  alert(this);
});

输出:

one   two  three  four   five

var arr2 = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
$.each(arr2, function(i, item){
  alert(item[0]);
});

输出:

1   4   7

var obj = { one:1, two:2, three:3, four:4, five:5 };
$.each(obj, function(key, val) {
  alert(obj[key]);
});

输出:

1   2  3  4  5

//json格式
var param = [{'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);
  var taskParam = param[0].taskParam ;
  //遍历任务参数数组
  jQuery.each(taskParam,function(i, item){
    //解析单个任务参数
    jQuery.each(item ,function(key){
      alert(key);//key
            alert(item[key]);//value
          });
  });
}

PS:关于json操作,这里再为大家推荐几款比较实用的json在线工具供大家参考使用:

在线JSON代码检验、检验、美化、格式化工具:
http://tools.softyun.net/code/json

JSON在线格式化工具:
http://tools.softyun.net/code/jsonformat

在线XML/JSON互相转换工具:
http://tools.softyun.net/code/xmljson

json代码在线格式化/美化/压缩/编辑/转换工具:
http://tools.softyun.net/code/jsoncodeformat

在线json压缩/转义工具:
http://tools.softyun.net/code/json_yasuo_trans

希望本文所述对大家jQuery程序设计有所帮助。

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们