所以我的代码在这里返回Promise,并且由于我使用的是then
语法,所以我不知道为什么会这样:-??
fetch('someurltoAJsonFile.json')
.then(function(response) {
console.log(response.json());});
node-fetch库中的response.json()也返回一个promise,而是尝试
fetch('someurltoAJsonFile.json')
.then(response => response.json())
.then(data => {
console.log(data)
});
您可以在此处查找有关它的更多详细信息
编辑:
似乎返回的响应不在有效的json中,因此为了完整起见,这里是文本代码
fetch('someurltoAJsonFile.json')
.then(response => response.text())
.then(data => {
console.log(data)
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句