我如何从以下回复中获得标题

how i get title from following response

如何从以下 json 回复中获取标题或 body?

{
    "message": "All Books",
    "data": {
        "current_page": 1,
        "data": [
            {
                "id": 2,
                "title": "The Quran",
                "slug": "the-quran",
                "body": "The Holy Quran",
                "book": "/storage/books/1602685137.pdf",
                "cover": "/storage/covers/1602685137.jpg",
                "os": "both",
                "price_ios": 0,
                "price_android": 0,
                "created_at": "2020-10-14T14:18:57.000000Z",
                "updated_at": "2020-10-14T14:18:57.000000Z"
            }
        ],
        "first_page_url": "https://book.test/api/v1/books?page=1",
        "from": 1,
        "last_page": 1,
        "last_page_url": "https://book.test/api/v1/books?page=1",
        "links": [
            {
                "url": null,
                "label": "Previous",
                "active": false
            },
            {
                "url": "https://book.test/api/v1/books?page=1",
                "label": 1,
                "active": true
            },
            {
                "url": null,
                "label": "Next",
                "active": false
            }
        ],
        "next_page_url": null,
        "path": "https://book.test/api/v1/books",
        "per_page": 15,
        "prev_page_url": null,
        "to": 1,
        "total": 1
    }
}

假设您的 JSON 被分配给一个名为 response 的变量,您可以通过以下方式访问 body:
let body = response.data.data[0].body

并且标题带有
let title = response.data.data[0].title

如果您想遍历数据数组以获取所有条目(例如标题)的值,请尝试以下操作:
let titles = response.data.data.forEach(entry => console.log(entry.title));

假设 json 存储在变量 res.

由于第二个数据对象存储为数组[].

title = res['data']['data'][0]['title'];
body = res['data']['data'][0]['body'];

如果你发现数组中有多个对象,那么你将不得不将0更改为数组中对象的索引。 参考:www.json.org