Reputation: 11
The back-end generated the data API, and how to fetch data on the front end ps: I use react
URL: http://localhost:8080/api/barrages
{
"content": [
{
"key": 12344443434545435,
"text": "绿色走一波",
"time": 500,
"fontFamily": null,
"fontsize": null,
"color": "#0f0",
"video_id": null,
"creationDateTime": "2019-04-08T13:59:51Z"
}
],
"page": 0,
"size": 30,
"totalElements": 1,
"totalPages": 1,
"last": true
}
fetch("/api/barrages", { method: 'GET' })
.then(function (res) {
res.json()
.then(function (barrage) {
console.log(barrage);
}
)
})
I want to get the data of content
Upvotes: 0
Views: 3544
Reputation: 15688
You would need to do it like this:
fetch("/api/barrages", { method: 'GET' })
.then(function (res) {
return res.json()
}
.then(function(myJson){
console.log(JSON.stringify(myJson))
})
})
Upvotes: 1