2015-11-28 31 views
0

我正在使用Amazon Web Services數據庫dynamodb。它返回AA JSON看起來liek這樣的:訪問JSON回覆

{"Responses":{"friends":[{"to_username":"u1","from_username":"u2"}]},"UnprocessedKeys":{}} 

我需要朋友數組的長度並同時獲得單個值(例如to_username在數組的第一個元素是「U1」中的例子) 。

我已經試過這樣的事情:

console.log(data.responses.friends.length); //get length (data is the object I get returned from my async call 
console.log(data.responses.friends.to_username[0]); //get to_username of the first element in the array 

兩個返回undefined。

+2

'respond!= Responses' – adeneo

回答

1

案件事宜!

console.log(data.Responses.friends.length); //get length (data is the object I get returned from my async call 
console.log(data.Responses.friends.to_username[0]); //get to_username of the first element in the array 

產生正確的結果。請注意響應中的大寫字母R.

+0

O我的天哪,我花了一個多小時試圖弄清楚什麼是錯的。現在非常感謝你的作品!我真是個假人! – user2924127

1

Javascript是一個case sensitive的語言。請確保您的代碼中的大小寫與您的回覆中的大小寫匹配。