主要對象,我有以下JSON:循環執行JSON不具備陣列
basket = {
"Items": 3,
"Item": {
"iPhone 6": {
"productId": 227,
"url": "http://example.com/iphone6",
"price": 299.99
},
"Solio Mono Solar Charger": {
"productId": 655,
"url": "http://website.com/solio_charger.html",
"price": 29.95
},
"24 Month Warranty Package": {
"productId": 681,
"url": "http://website.com/24_month_warranty.html",
"price": 129.95
}
},
"Total": 459.89
}
我想在basket['Item']
遍歷所有的對象,但是JSON本身並沒有提供一個數組的話,循環basket['item']
中的對象的最佳方法是什麼?
有很多方法可以做到這一點 - 你嘗試過什麼? –
你可以檢查這個線程:http://stackoverflow.com/questions/1078118/how-do-i-iterate-over-a-json-structure – Armen