【发布时间】:2021-09-14 21:44:10
【问题描述】:
我正在使用 node.js。我使用 JSON 从文件中读取对象。
vc_channels.json 文件:
{
"hangout-room": "hangout-room is a voice and/or video room for anything sfw and not necessarily related to meditation."
}
要阅读的代码:
fileContent = fs.readFileSync('./vc_channels.json');
vc_channels = JSON.parse(fileContent);
但是当我尝试访问时:
console.log(vc_channels);
console.log(channel.name);
item.topic = vc_channels[channel.name];
console.log(item.topic);
结果未定义:console.log
{
'hangout-room': 'hangout-room is a voice and/or video room for anything sfw and not necessarily related to meditation.'
}
hangout-room
undefined
有人知道我做错了什么吗?
【问题讨论】:
标签: javascript node.js json