json - React native fetch 返回 _bodyBlob _bodyInit 标头等,而不是带有 json() 的 json
问题描述
在重新安装 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。不是我...
解决方案
我的错。或不。我不知道你告诉我。我替换为:
export function test() {
return fetch('http://url/api/testServlet')
.then((response) => response.json())
.then((responseJson) => {
console.log("data : ", responseJson)
return responseJson;
})
.catch((error) => {
console.error(error);
});
}
它奏效了。它可能来自我不知道的 const url,但我很高兴。谢谢你。或者谢谢我,我不知道你告诉我。
推荐阅读
- django - 添加按钮以添加学生 Django 管理员
- python - 可以与 Zookeeper 对话,但不能与消息代理对话
- java - Java- 在 JOptionPane 上读取输入和输出
- python - Python - 如何与系统托盘弹出交互
- ruby - 如果函数没有存储在变量中,是否可以获得将从函数返回的值?
- java - 使用 Jackson 将 Json 解析为 POJO
- python - 将 2D 箱中的散点平均值绘制为直方图/hexplot
- dns - 将 Godaddy 域转移到 Azure 应用服务
- python - Python中的菜单函数和类
- telnet - Telnet Will TN3270E 和 Telnet Wont TN3270E 的区别