TypeError:无法读取未定义的属性(reading' name');

发布于 2025-02-09 19:04:17 字数 595 浏览 2 评论 0原文

错误:

无法读取未定义的属性(读取名称')

代码的属性:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

美羊羊 2025-02-16 19:04:18

数据 array ,您无法做data.name
之类的事情
您需要使用一些数组方法来访问Data中的信息,或者仅仅在这种情况下指定数组中的精确索引,因为data data 代码>数组中只有一个项目,但这是不可扩展的...

body.data.map(((currentElement)=&gt; {console.log(currentelement.name)} < br>
并应打印“开发”。

data is an array, you can not do things like that data.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 is 0 because the data 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.

林空鹿饮溪 2025-02-16 19:04:18

body.data.nameres.data.name

Replace body.data.name with res.data.name

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文