【发布时间】:2020-01-08 14:32:08
【问题描述】:
重新安装 node_modules 并将 json() 用于我的 fetch 调用后,我仍然收到 blob 响应。这是我的代码:
export function test() {
const url = 'http://url/api/testServlet';
return fetch(url, {
method: 'GET',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
})
.then((data) => {
console.log("data ", data, " --- end data");
data.json();
})
.catch((error) => {
console.error(error);
});
}
使用 console.log,我得到:
data
{
"_bodyBlob": {
blob
},
"_bodyInit": {
blob
},
"headers": {
headers
},
"ok": true,
"status": 200,
"statusText": undefined,
"type": "default",
"url": "http://url/api/testServlet"
}
--- fin data
非常感谢您的帮助
编辑: 我还有一个错误 value.hasOwnProperty('tag') 来自任何地方我完全不知道它来自哪里......我只有一个显示我的 API 调用结果和上面显示的代码的组件。 消息是: "错误:value.hasOwnProperty 不是函数。(在'value.hasOwnProperty('tag')中,'value.hasOwnProperty'未定义)
我阅读了一些主题,所有人都在谈论这个错误,但是代码中写了函数 hasOwnProperty。不是我……
【问题讨论】:
标签: json api react-native fetch blob