2012-10-13 23 views
-1

可能重複:
I have a nested data structure/JSON, how can access a specific value?我如何可以訪問以下JSON 「名稱和商店的名字」

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

它的JSON數據,我怎麼能使用Ajax或Javasricpt閱讀

+0

僅供參考,表達 「阿賈克斯或JavaScript」 沒有多大意義。 「Ajax」是* Asynchronous JavaScript And XML *的縮寫,即Ajax構建於JavaScript之上。 –

回答

1

列表和商店是一個數組,因此要檢索名稱和商店的名稱,使用像這樣的數組索引:

jsondata.List[0].Name >>> return "VMW" 
jsondata.List[0].Stores[0].Name >>> return "Admin" 
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" 
相關問題