可能重复:
我有一个嵌套数据结构/JSON,如何访问特定值?
{
"List":
[
{"Active":true,"Name":"VMW","Stores":
[
{"Active":true,"Name":"Admin"},{"Active":true,"Name":"sunil"}
]
}
]
}
它的 json 数据,我如何使用 Ajax 或 Javasricpt 读取它
可能重复:
我有一个嵌套数据结构/JSON,如何访问特定值?
{
"List":
[
{"Active":true,"Name":"VMW","Stores":
[
{"Active":true,"Name":"Admin"},{"Active":true,"Name":"sunil"}
]
}
]
}
它的 json 数据,我如何使用 Ajax 或 Javasricpt 读取它
List 和 store 是一个数组,因此要检索名称和 store 的名称,请使用数组索引,如下所示:
jsondata.List[0].Name >>> return "VMW"
jsondata.List[0].Stores[0].Name >>> return "Admin"
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"