TypeError:无法读取未定义的属性(reading' name');
错误:
无法读取未定义的属性(读取名称')
代码的属性:
function loop(){
request.get({
url: 'https://games.roblox.com/v1/games?universeIds=3652651589',
rejectUnauthorized: false,
headers: {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3750.0 Iron Safari/537.36'
}
}, (err, res, body) => {
console.log(body.data.name)
});
setTimeout(loop, 5000);
}
loop();
我该怎么办?
Error:
Cannot read properties of undefined (reading 'name')
Code:
function loop(){
request.get({
url: 'https://games.roblox.com/v1/games?universeIds=3652651589',
rejectUnauthorized: false,
headers: {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3750.0 Iron Safari/537.36'
}
}, (err, res, body) => {
console.log(body.data.name)
});
setTimeout(loop, 5000);
}
loop();
What must I do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
数据
是 array ,您无法做data.name
之类的事情
您需要使用一些数组方法来访问
Data
中的信息,或者仅仅在这种情况下指定数组中的精确索引,因为data
data 代码>数组中只有一个项目,但这是不可扩展的...body.data.map(((currentElement)=> {console.log(currentelement.name)}
< br>并应打印“开发”。
data
is an array, you can not do things like thatdata.name
You need to use some array methods to access the information in the
data
or simply to specify exact index in the array in this case is0
because thedata
array has only one item in it, but this is kind of not scalable...body.data.map((currentElement) => { console.log(currentElement.name) }
and "On Development" should be printed.
body.data.name
用res.data.name
Replace
body.data.name
withres.data.name