后端生成数据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);
}
)
})
我想获取内容的数据
最佳答案
你需要这样做:
fetch("/api/barrages", { method: 'GET' })
.then(function (res) {
return res.json()
}
.then(function(myJson){
console.log(JSON.stringify(myJson))
})
})
关于javascript - 如何从后端获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55980618/