1、遍历Json对象
myJson = {"name":"nikita", "password":"1111"}; for(var p in myJson){//遍历json对象的每个key/value对,p为key alert(p + " " + myJson[p]); }
2、遍历Json对象数组
packJson = [ {"name":"nikita", "password":"1111"}, {"name":"tony", "password":"2222"} ]; for(var p in packJson){//遍历json数组时,这么写p为索引,0,1 alert(packJson[p].name + " " + packJson[p].password); }