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); }