在JavaScript中解析Json数组

时间:2018-03-15 13:41:10

标签: javascript arrays json

  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数组的值?

2 个答案:

答案 0 :(得分:0)

您不能将数组用作变量,因此请替换为arr并尝试关注,



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




答案 1 :(得分:0)

array.forEach(item => console.log(item.Name))

array.forEach(item => console.log(item.Status.Id))