gpt4 book ai didi

javascript - 访问 JSON 回复

转载 作者:行者123 更新时间:2023-12-02 15:21:54 26 4
gpt4 key购买 nike

我正在使用 Amazon Web Services 数据库 dynamodb。它返回一个 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

两者都返回未定义。

最佳答案

大小写很重要!

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。

关于javascript - 访问 JSON 回复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33977158/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com