這可能是重複的問題,因爲我不知道我有什麼搜索每天得到解決無法從JSON獲取數據對象
我工作的JSON,字符串數組和解析,所以我從API獲取價值並不算太長,但現在我很困惑。我正在從我的API這個JSON字符串,下面是我的整個響應
{
"data": {
"6402902233557646": {
"_geo_node": {
"name": "Dev",
"tags": {
"property_type": ["Dev"],
"_listing_type": ["_main"],
"others": ["_hotel"]
},
"raw_tags": [],
"location": {
"lat": 22.9745967,
"long": 72.5615485
},
"_id": "6402902233557646",
"type": 120
},
"_data_node": {
"rating": 0,
"img_processed": [],
"name": "Dev",
"ids": {},
"st": "LIV",
"_id": "6402902233557646"
}
},
"6402902233557647": {},
"6402902233557648": {},
"6402902233557649": {}
},
"t": 1144.423,
"success": true
}
的一些價值觀和我想我已經嘗試下面不同的術語這個
var getData = JSON.parse(response); //Error: Already Parsed
alert(response.success); //OK true
alert(response.t); //OK 1144.423
從此獲得單值
這裏有一個問題
alert(response.data.length) //Undefined
alert(response.data) // [object,object]
alert(response.data[0]["_geo_node"]["name"]); //TypeError: response.data[0] is undefined
我不知道爲什麼我收到這個不確定的或者我錯過了點
'response.data'不是array.its的對象。 –
術語pedantry:[沒有這種東西作爲「JSON對象」。](http://benalman.com/news/2010/03/theres-no-such-thing-as-a-json/) – nnnnnn
它是真的很好,我明白這一點,我第一次有這種類型的API,但接下來我肯定會爲此做更多的工作。這次真是萬分感謝。 –