-1

可能重复:
我有一个嵌套数据结构/JSON,如何访问特定值?

{
"List":
  [
     {"Active":true,"Name":"VMW","Stores":
      [
        {"Active":true,"Name":"Admin"},{"Active":true,"Name":"sunil"}
      ]
     }
  ]
}

它的 json 数据,我如何使用 Ajax 或 Javasricpt 读取它

4

2 回答 2

1

List 和 store 是一个数组,因此要检索名称和 store 的名称,请使用数组索引,如下所示:

jsondata.List[0].Name >>> return "VMW"
jsondata.List[0].Stores[0].Name >>> return "Admin"
于 2012-10-13T08:37:07.780 回答
0
json = {
"List":
  [
     {"Active":true,"Name":"VMW","Stores":
      [
        {"Active":true,"Name":"Admin"},{"Active":true,"Name":"sunil"}
      ]
     }
  ]
}

json["List"]  // { "Active":true,"Name":"VMW","Stores": [{"Active":true,"Name":"Admin"},{"Active":true,"Name":"sunil"}]}


json["List"][0]["Stores"] // {"Active":true,"Name":"Admin"},{"Active":true,"Name":"sunil"}

是对象的存储

Stores = json["List"][0]["Stores"]

for (i in Stores) (function(active, name) {


    console.log(active, name);
}(Stores[i]["Active"], Stores[i]["Name"]));

结果:

true "Admin"
true "sunil"
于 2012-10-13T08:45:15.217 回答