转 json格式 Js里循环遍历json格式数据

json格式 Js里循环遍历json格式数据
分类: JavaScript 2010-12-17 12:20 1035人阅读 评论(0) 收藏 举报

什么是JOSN

http://www.cnblogs.com/gooddasenlin/archive/2009/05/31/1493116.html



view plainprint?

   1. var list = {'list':[{"id":8,"password":"月月","username":"维吾尔"}, 
   2.  {"id":7,"password":"dfgsfdf","username":"dfdfdf"}, 
   3.  {"id":6,"password":"aaabbb","username":"aaaabbb"}, 
   4.  {"id":5,"password":"gfdfgdf","username":"fggegte"}, 
   5.  {"id":3,"password":"dfgfgrewr","username":"hahaha"}, 
   6.  {"id":2,"password":"fggfhgfh","username":"fddgfgh"}, 
   7.  {"id":1,"password":"hdghdgd","username":"dfsgss"}]}; 
   8.  
   9.   
  10. for(var l in list){   
  11.     alert(l+"  "+list[l]); 
  12.     for(var c in list[l]){ 
  13.         alert(list[l][c].id+"  "+list[l][c].password+"  "+list[l][c].username); 
  14.     } 
  15. } 
  16.   
  17. for(var l in list){   
  18.     alert(l+"  "+list[l]); 
  19.     for(var c in list[l]){ 
  20.         for(var _c in list[l][c]){ 
  21.             alert(_c+"  "+list[l][c][_c]); 
  22.         }; 
  23.     } 
  24. } 
  25.   
  26. var li = [{"id":8,"password":"月月","username":"维吾尔"}, 
  27.  {"id":7,"password":"dfgsfdf","username":"dfdfdf"}, 
  28.  {"id":6,"password":"aaabbb","username":"aaaabbb"}, 
  29.  {"id":5,"password":"gfdfgdf","username":"fggegte"}, 
  30.  {"id":3,"password":"dfgfgrewr","username":"hahaha"}, 
  31.  {"id":2,"password":"fggfhgfh","username":"fddgfgh"}, 
  32.  {"id":1,"password":"hdghdgd","username":"dfsgss"}]; 
  33.  
  34. for(var i in li){ 
  35.     alert(i+"  "+li[i]); 
  36.     for(var _i in li[i]){ 
  37.         alert(_i+"  "+li[i][_i]); 
  38.     }    
  39. } 

var list = {'list':[{"id":8,"password":"月月","username":"维吾尔"}, {"id":7,"password":"dfgsfdf","username":"dfdfdf"}, {"id":6,"password":"aaabbb","username":"aaaabbb"}, {"id":5,"password":"gfdfgdf","username":"fggegte"}, {"id":3,"password":"dfgfgrewr","username":"hahaha"}, {"id":2,"password":"fggfhgfh","username":"fddgfgh"}, {"id":1,"password":"hdghdgd","username":"dfsgss"}]}; for(var l in list){ alert(l+" "+list[l]); for(var c in list[l]){ alert(list[l][c].id+" "+list[l][c].password+" "+list[l][c].username); } } for(var l in list){ alert(l+" "+list[l]); for(var c in list[l]){ for(var _c in list[l][c]){ alert(_c+" "+list[l][c][_c]); }; } } var li = [{"id":8,"password":"月月","username":"维吾尔"}, {"id":7,"password":"dfgsfdf","username":"dfdfdf"}, {"id":6,"password":"aaabbb","username":"aaaabbb"}, {"id":5,"password":"gfdfgdf","username":"fggegte"}, {"id":3,"password":"dfgfgrewr","username":"hahaha"}, {"id":2,"password":"fggfhgfh","username":"fddgfgh"}, {"id":1,"password":"hdghdgd","username":"dfsgss"}]; for(var i in li){ alert(i+" "+li[i]); for(var _i in li[i]){ alert(_i+" "+li[i][_i]); } }







var obj = [ {"date":"2010-12-19", "price":123},
{"date":"2010-12-12", "price":33},
{"date":"2010-12-21", "price":444}
];

for(var i=0;i<obj.length;i++){
  if(obj[i].date == '2010-12-12'){
     return obj[i].price
  }
}

你可能感兴趣的:(json)