首页 > 解决方案 > 将对象获取到 HTML 页面

问题描述

fetch("https://jsonplaceholder.typicode.com/todos/1")
    .then(res => {res.json()})
    .then((body) => {
        console.log(body.title);
    })

我正在尝试在此 JSON 中获取标题对象,但我不明白为什么我总是收到此错误,是因为我没有运行服务器吗?

index.html:8 Uncaught (in promise) TypeError: Cannot read property 'title' of undefined at index.html:8

标签: javascriptjsonobjectfetch

解决方案


推荐阅读