gpt4 book ai didi

javascript - 从 JSON 对象中提取数据

转载 作者:行者123 更新时间:2023-11-28 19:04:55 24 4
gpt4 key购买 nike

我正在尝试从此 JSON 返回中提取文本:

{
"threaded_extended": {},
"messages": [
{
"body": {
"parsed": "the network. Take a moment to welcome Jason.",
"plain": " network. Take a moment to welcome Jason.",
"rich": "Jason."
},
"thread_id": 56,
"client_type": "Wb",
"client_url": "https://www.yammer.com/",
"system_message": true,
"direct_message": false,
"chat_client_sequence": null,
"language": "en",
"notified_user_ids": [],
"system_message_properties": {
"subtype": "created_membership"
},
"privacy": "public",
"attachments": [],
"liked_by": {
"count": 0,
"names": []
},
"content_excerpt": " Jason.",
"group_created_id": null
}
]

}我的函数看起来像这样,但它一直说未定义 - 抱歉,如果这是一个愚蠢的问题,我的逻辑是对象是值,然后消息是一个属性,然后 plain 应该是它的一个属性。我是不是在做蠢事?感谢任何帮助

function getData(returnData){
$.each(returnData, function(key, value){
if(value != undefined){
$('#test').append(value.messages.plain);
}
});
}

最佳答案

 $('#test').append(value.messages[0].plain);

messages 是一个数组,因此您需要提供索引。

<小时/>

编辑:我认为 returnData 是一个数组,如果不是这样的话,你循环的对象是错误的。循环遍历returnData.messages。并获取 value.body.plain

关于javascript - 从 JSON 对象中提取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31881460/

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