js遍历json对象
2021-07-13 02:07
标签:art rtm i++ return pack ack iba 对象 alert 原生js遍历json对象 遍历json对象: 无规律: var json = [ {dd:‘SB‘,AA:‘东东‘,re1:123}, {cccc:‘dd‘,lk:‘1qw‘} ]; for(var i=0,l=json.length;i for(var key in json[i]){ alert(key+‘:‘+json[i][key]); } } 有规律: 也可以用这个: 遍历json对象 有如下 json对象: var obj ={"name":"冯娟","password":"123456","department":"技术部","sex":"女","old":30}; 遍历方法: js遍历json对象 标签:art rtm i++ return pack ack iba 对象 alert 原文地址:http://www.cnblogs.com/qingqingzou-143/p/7079725.htmlpackJson = [
{"name":"nikita", "password":"1111"},
{"name":"tony", "password":"2222"}
];
for(var p in packJson){//遍历json数组时,这么写p为索引,0,1
alert(packJson[p].name + " " + packJson[p].password);
}
for(var i = 0; i
myJson = {"name":"caibaojian", "password":"1111"};
for(var p in myJson){//遍历json对象的每个key/value对,p为key
alert(p + " " + myJson[p]);
}
for(var p in obj){
str = str+obj[p]+‘,‘;
return str;
}
下一篇:js格式化时间