2016-08-21 184 views
-1

我有一個JSON對象如下:從JSON數據獲取的值對象

Returned json object

如何檢索列「ID_Entreprise」的價值。 我試圖console.log(data.rows[0].ID_Entreprise);

,但它給了我下面的錯誤:

ModalForms.js:567 Uncaught TypeError: Cannot read property '0' of undefined

+0

只是一個想法 - 你試過資本'Data'? –

回答

2

你有兩個問題:

  1. 你需要開始與持有該對象的變量,而不是數據屬性在對象內部。
  2. 該數據屬性被稱爲Data,而不是data。 (請記住,情況事項)

假設你的目標是在變量jsonObject,你可以使用:

jsonObject.Data.rows[0].ID_Entreprise 
+0

感謝您的提示。它確實工作,正確的語法竟然是: console.log(data.Data.rows [0] .ID_Entreprise) – Patrice

+0

@Patrice,作爲一個友好的提醒,在StackOverflow上做的正確/禮貌的事情是接受最好的解決你的問題的答案。 – DocMax

+0

對不起, 甚至不知道如何「接受答案」。當我想登錄並閱讀我的帖子時,我頭痛的註冊了更多。 – Patrice