我只是在學習json。我試圖創建對象的消息的數組,該聲明並沒有給我一個錯誤,但是當我嘗試使用下面的代碼 serverReply2.Mesages[0].Date
來訪問它,我得到一個錯誤:試圖在javascript中創建一個json數組
Uncaught TypeError: Cannot read property '0' of undefined
代碼:
this.serverReply2 = {"Messages": [
{"Date": "1/1/1",
"Mwessage": "test messageA",
"Attachmentsd": ["link2","link2"]},
{"Date": "1/1/2",
"Mwessage": "test messageB",
"Attachmentsd": ["link2","link2"]},
{"Date": "1/1/3",
"Mwessage": "test messageC",
"Attachmentsd": ["link2","link2"]},
]
};
alert(serverReply2.Mesages[0].Date);
你已經寫了Mesages而不是Messages。 – Gazler 2012-01-16 22:19:00
和serverReply2而不是this.serverReply2 – vaugham 2012-01-16 22:21:11