本文實(shí)例講述了jQuery解析json格式數(shù)據(jù)。分享給大家供大家參考,具體如下:
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'}]}];//設(shè)置參數(shù)值if(param.length>0){  alert(param[0].subJobClass);  alert(param[0].subJobMethod);  var taskParam = param[0].taskParam ;  //遍歷任務(wù)參數(shù)數(shù)組  jQuery.each(taskParam,function(i, item){    //解析單個(gè)任務(wù)參數(shù)    jQuery.each(item ,function(key){      alert(key);//key            alert(item[key]);//value          });  });}感興趣的朋友可以使用在線HTML/CSS/JavaScript代碼運(yùn)行工具:http://tools.Vevb.com/code/HtmlJsRun測(cè)試上述代碼運(yùn)行效果。
PS:關(guān)于json操作,這里再為大家推薦幾款比較實(shí)用的json在線工具供大家參考使用:
在線JSON代碼檢驗(yàn)、檢驗(yàn)、美化、格式化工具:
http://tools.Vevb.com/code/json
JSON在線格式化工具:
http://tools.Vevb.com/code/jsonformat
在線XML/JSON互相轉(zhuǎn)換工具:
http://tools.Vevb.com/code/xmljson
json代碼在線格式化/美化/壓縮/編輯/轉(zhuǎn)換工具:
http://tools.Vevb.com/code/jsoncodeformat
在線json壓縮/轉(zhuǎn)義工具:
http://tools.Vevb.com/code/json_yasuo_trans
更多關(guān)于jQuery相關(guān)內(nèi)容還可查看本站專(zhuān)題:《jQuery操作json數(shù)據(jù)技巧匯總》、《jQuery常用插件及用法總結(jié)》、《jQuery擴(kuò)展技巧總結(jié)》及《jquery選擇器用法總結(jié)》
希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選