Parse Json array in JavaScript
本问题已经有最佳答案,请猛点这里访问。
1 2 3 4 5 | var array= [ {"Name":"Test","Status":{"Id":100,"Alias":"A"}}, {"Name":"Test2","Status":{"Id":101,"Alias":"B"}}, {"Name":"Test3","Status":{"Id":102,"Alias":"C"}} ]; |
如何在javascript中循环抛出name和id数组的值?
1 2 3 | array.forEach(item => console.log(item.Name)) array.forEach(item => console.log(item.Status.Id)) |
不能将数组用作变量,因此请替换为
1 2 3 4 5 6 7 8 9 10 | var arr = [ {"Name":"Test","Status":{"Id":100,"Alias":"A"}}, {"Name":"Test2","Status":{"Id":101,"Alias":"B"}}, {"Name":"Test3","Status":{"Id":102,"Alias":"C"}} ]; arr.forEach(function(item){ console.log('Name: ' + item.Name); console.log('Status Id: ' + item.Status.Id); console.log('Status Alias: ' + item.Status.Alias); }); |