api - 在 react-native 中将数据提取到数据库时出现问题。错误:“json parse error unrecognized token '<'”
问题描述
try {
return fetch('http://mylinktoAPI', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
},
body: JSON.stringify({
first_name: this.state.first_name,
last_name: this.state.last_name,
gender: this.state.gender,
blood_group: this.state.blood_group,
phone: this.phone,
email: this.email,
address: this.address,
}),
}).then((response) => response.json())
.then((responseJson) => {
Alert.alert(responseJson);
}).catch((error) => {
console.error(error);
});
} catch (e) {
console.error('fetch catch error', e);
}
};
解决方案
在标题中,您可以尝试将 Content-Type 更改为"application/json"
"Content-Type", "application/json"
推荐阅读
- javascript - 存储在 asp.net core 2.0 中的会话变量第一次给出 null 并且在刷新时工作正常
- android - 如何将原始 H.264 帧流式传输到 Windows 10 UWP?
- vba - VBA - 仅在 ActiveSheet 上的命令按钮计数
- php - SonataUserBundle + FOSUserBundle 注解问题学说主键错误
- python - 使用 OSMNx 绘制多条路线
- angular - Angular-CLI: How to use `ng build --prod` command for with environment.staging.ts?
- css - 为什么 Chrome 不为按钮呈现字体系列?
- matlab - 使用 UINT16 数据类型时。matlab和opencv之间调整大小有什么区别?
- javascript - 使用未定义的常量 jquery - 假定为 'jquery' - Wordpress
- c++ - static_cast 的指针值