首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

操作json数据,该怎么处理

2013-09-07 
操作json数据[{id:440,name:1单元,famliys:[{id:441,floor:1,name:101},{id:442,floor

操作json数据
[{"id":440,"name":"1单元","famliys":[{"id":441,"floor":1,"name":"101"},{"id":442,"floor":1,"name":"102"},{"id":443,"floor":2,"name":"201"},{"id":444,"floor":2,"name":"202"},{"id":445,"floor":3,"name":"301"},{"id":446,"floor":3,"name":"302"},{"id":447,"floor":4,"name":"401"},{"id":448,"floor":4,"name":"402"},{"id":449,"floor":5,"name":"501"},{"id":450,"floor":5,"name":"502"},{"id":451,"floor":6,"name":"601"},{"id":452,"floor":6,"name":"602"}]},{"id":453,"name":"2单元","famliys":[{"id":454,"floor":1,"name":"101"},{"id":455,"floor":1,"name":"102"},{"id":456,"floor":2,"name":"201"},{"id":457,"floor":2,"name":"202"},{"id":458,"floor":3,"name":"301"},{"id":459,"floor":3,"name":"302"},{"id":460,"floor":4,"name":"401"},{"id":461,"floor":4,"name":"402"},{"id":462,"floor":5,"name":"501"},{"id":463,"floor":5,"name":"502"},{"id":464,"floor":6,"name":"601"},{"id":465,"floor":6,"name":"602"}]},{"id":466,"name":"3单元","famliys":[{"id":467,"floor":1,"name":"101"},{"id":468,"floor":1,"name":"102"},{"id":469,"floor":2,"name":"201"},{"id":470,"floor":2,"name":"202"},{"id":471,"floor":3,"name":"301"},{"id":472,"floor":3,"name":"302"},{"id":473,"floor":4,"name":"401"},{"id":474,"floor":4,"name":"402"},{"id":475,"floor":5,"name":"501"},{"id":476,"floor":5,"name":"502"},{"id":477,"floor":6,"name":"601"},{"id":478,"floor":6,"name":"602"}]},{"id":479,"name":"4单元","famliys":[{"id":480,"floor":1,"name":"101"},{"id":481,"floor":1,"name":"102"},{"id":482,"floor":2,"name":"201"},{"id":483,"floor":2,"name":"202"},{"id":484,"floor":3,"name":"301"},{"id":485,"floor":3,"name":"302"},{"id":486,"floor":4,"name":"401"},{"id":487,"floor":4,"name":"402"},{"id":488,"floor":5,"name":"501"},{"id":489,"floor":5,"name":"502"},{"id":490,"floor":6,"name":"601"},{"id":491,"floor":6,"name":"602"}]}]



以上这个的json数据

怎么用jquery 的each 循环遍历出来呢 
 

求解答操作json数据,该怎么处理


[解决办法]
$.each(你的数组,function(){
   你的数组里每个数据的操作方法
})
[解决办法]

引用:
var test=[{"id":440,"name":"1单元","famliys":[{"id":441,"floor":1,"name":"101"},{"id":442,"floor":1,"name":"102"},

{"id":443,"floor":2,"name":"201"},{"id":444,"floor":2,"name":"202"},{"id":445,"floor":3,"name":"301"},



{"id":446,"floor":3,"name":"302"},{"id":447,"floor":4,"name":"401"},{"id":448,"floor":4,"name":"402"},

{"id":449,"floor":5,"name":"501"},{"id":450,"floor":5,"name":"502"},{"id":451,"floor":6,"name":"601"},

{"id":452,"floor":6,"name":"602"}]},{"id":453,"name":"2单元","famliys":[{"id":454,"floor":1,"name":"101"},

{"id":455,"floor":1,"name":"102"},{"id":456,"floor":2,"name":"201"},{"id":457,"floor":2,"name":"202"},

{"id":458,"floor":3,"name":"301"},{"id":459,"floor":3,"name":"302"},{"id":460,"floor":4,"name":"401"},

{"id":461,"floor":4,"name":"402"},{"id":462,"floor":5,"name":"501"},{"id":463,"floor":5,"name":"502"},

{"id":464,"floor":6,"name":"601"},{"id":465,"floor":6,"name":"602"}]},{"id":466,"name":"3单元","famliys":

[{"id":467,"floor":1,"name":"101"},{"id":468,"floor":1,"name":"102"},{"id":469,"floor":2,"name":"201"},

{"id":470,"floor":2,"name":"202"},{"id":471,"floor":3,"name":"301"},{"id":472,"floor":3,"name":"302"},

{"id":473,"floor":4,"name":"401"},{"id":474,"floor":4,"name":"402"},{"id":475,"floor":5,"name":"501"},

{"id":476,"floor":5,"name":"502"},{"id":477,"floor":6,"name":"601"},{"id":478,"floor":6,"name":"602"}]},

{"id":479,"name":"4单元","famliys":[{"id":480,"floor":1,"name":"101"},{"id":481,"floor":1,"name":"102"},

{"id":482,"floor":2,"name":"201"},{"id":483,"floor":2,"name":"202"},{"id":484,"floor":3,"name":"301"},

{"id":485,"floor":3,"name":"302"},{"id":486,"floor":4,"name":"401"},{"id":487,"floor":4,"name":"402"},

{"id":488,"floor":5,"name":"501"},{"id":489,"floor":5,"name":"502"},{"id":490,"floor":6,"name":"601"},

{"id":491,"floor":6,"name":"602"}]}];
 
  $.each(test, function(idx,item) {
 
alert("外层id:"+item.id+",name:"+item.name); 
var famliys=item.famliys;
$.each(famliys, function(i,e){
alert("内层id:"+e.id+",floor"+e.floor+",name:"+e.name); 

})

})
});

操作json数据,该怎么处理
[解决办法]
function jsonEval(){
var i= "[{"id":440,"name":"1单元","famliys":[{"id":441,"floor":1,"name":"101"},{"id":442,"floor":1,"name":"102"},{"id":443,"floor":2,"name":"201"},{"id":444,"floor":2,"name":"202"},{"id":445,"floor":3,"name":"301"},{"id":446,"floor":3,"name":"302"},{"id":447,"floor":4,"name":"401"},{"id":448,"floor":4,"name":"402"},{"id":449,"floor":5,"name":"501"},{"id":450,"floor":5,"name":"502"},{"id":451,"floor":6,"name":"601"},{"id":452,"floor":6,"name":"602"}]},{"id":453,"name":"2单元","famliys":[{"id":454,"floor":1,"name":"101"},{"id":455,"floor":1,"name":"102"},{"id":456,"floor":2,"name":"201"},{"id":457,"floor":2,"name":"202"},{"id":458,"floor":3,"name":"301"},{"id":459,"floor":3,"name":"302"},{"id":460,"floor":4,"name":"401"},{"id":461,"floor":4,"name":"402"},{"id":462,"floor":5,"name":"501"},{"id":463,"floor":5,"name":"502"},{"id":464,"floor":6,"name":"601"},{"id":465,"floor":6,"name":"602"}]},{"id":466,"name":"3单元","famliys":[{"id":467,"floor":1,"name":"101"},{"id":468,"floor":1,"name":"102"},{"id":469,"floor":2,"name":"201"},{"id":470,"floor":2,"name":"202"},{"id":471,"floor":3,"name":"301"},{"id":472,"floor":3,"name":"302"},{"id":473,"floor":4,"name":"401"},{"id":474,"floor":4,"name":"402"},{"id":475,"floor":5,"name":"501"},{"id":476,"floor":5,"name":"502"},{"id":477,"floor":6,"name":"601"},{"id":478,"floor":6,"name":"602"}]},{"id":479,"name":"4单元","famliys":[{"id":480,"floor":1,"name":"101"},{"id":481,"floor":1,"name":"102"},{"id":482,"floor":2,"name":"201"},{"id":483,"floor":2,"name":"202"},{"id":484,"floor":3,"name":"301"},{"id":485,"floor":3,"name":"302"},{"id":486,"floor":4,"name":"401"},{"id":487,"floor":4,"name":"402"},{"id":488,"floor":5,"name":"501"},{"id":489,"floor":5,"name":"502"},{"id":490,"floor":6,"name":"601"},{"id":491,"floor":6,"name":"602"}]}]";


var temp = eval(i);
 $.each(temp, function(idx,item) {
 //外层操作
 var tl = item.famliys;
  $.each(tl,function(index,tem){
  //内层操作
  })
 });
}

热点排行