后端生成数据API,以及如何在前端获取数据ps:我使用react
网址:http://localhost:8080/api/barrages
当请求上述url时,浏览器显示如下。
{
"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);
}
)
})我想要获取内容的数据
发布于 2019-05-04 15:56:54
你需要这样做:
fetch("/api/barrages", { method: 'GET' })
.then(function (res) {
return res.json()
}
.then(function(myJson){
console.log(JSON.stringify(myJson))
})
})https://stackoverflow.com/questions/55980618
复制相似问题