gpt4 book ai didi

javascript - 访问不常见 JSON 对象中的数据

转载 作者:行者123 更新时间:2023-12-03 06:03:27 24 4
gpt4 key购买 nike

我需要在JS中访问JSON对象的特定内容,这是一个例子:

 _isEditedMessage: false,
_message:
Message {
_messageId: 0000,
_from:
User {
_id: 0000000,
_firstName: 'bbbb',
_lastName: null,
_username: 'aaaa' },
_date: 1474571521,
_chat:
Chat {
_id: 000000,
_type: 'private',
_title: null,
_username: 'aaaa',
_firstName: 'bbbb',
_lastName: null },
_forwardFrom: null,

我需要从 _firstName 访问名字,无论它是来自用户还是聊天。我知道我可以使用 $._isEditedMessage 访问 _isEditedMessage。我想要输出 bbbb

最佳答案

假设你的 JS 对象以 $ 开头,那么它就是

console.log($._message._from._firstName || $._message._chat._firstName);

关于javascript - 访问不常见 JSON 对象中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39650455/

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