本文實例講述了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 }); });}
感興趣的朋友可以使用在線HTML/CSS/JavaScript代碼運行工具:http://tools.VeVB.COm/code/HtmlJsRun測試上述代碼運行效果。
PS:關于json操作,這里再為大家推薦幾款比較實用的json在線工具供大家參考使用:
在線JSON代碼檢驗、檢驗、美化、格式化工具:
http://tools.VeVB.COm/code/json
JSON在線格式化工具:
http://tools.VeVB.COm/code/jsonformat
在線XML/JSON互相轉換工具:
http://tools.VeVB.COm/code/xmljson
json代碼在線格式化/美化/壓縮/編輯/轉換工具:
http://tools.VeVB.COm/code/jsoncodeformat
在線json壓縮/轉義工具:
http://tools.VeVB.COm/code/json_yasuo_trans
更多關于jQuery相關內容還可查看本站專題:《jQuery操作json數據技巧匯總》、《jQuery常用插件及用法總結》、《jQuery擴展技巧總結》及《jquery選擇器用法總結》
希望本文所述對大家jQuery程序設計有所幫助。
新聞熱點
疑難解答