json - 如何修复 ReactNative 中发送的“Json Parse Error: Unexpected EOF”错误?
问题描述
所以我正在开发一个 ReactNative 应用程序,并创建一个新用户,我正在使用用户提供的信息创建一个 Json,并将其发送到一个 PhP 文件,该文件解析 Json 接收到的将其存储在数据库中。但问题是我的 JSON 没有发送,而且我有这个宏伟的红屏“JSON 解析错误:意外 EOF”
这是我的 Fetch 代码:
Insert_Data_Into_MySQL = () =>
{
this.setState({ ActivityIndicator_Loading : true }, () =>
{
fetch('http://MyPathToMyServerButDontWorryItsAnExample/NewUser.php',
{
method: 'POST',
headers:
{
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(
{
product_name : this.state.Product_Name,
product_number : this.state.Product_Number,
product_details : this.state.Product_Details
})
})
.then((response) => response.json()).then((responseJsonFromServer) =>
{
Alert.alert(responseJsonFromServer);
this.setState({ ActivityIndicator_Loading : false });
}).catch((error) =>
{
console.error(error);
this.setState({ ActivityIndicator_Loading : false});
});
});
}
非常感谢你们!
解决方案
推荐阅读
- python - Python中graphviz模块遇到的问题 - Mac OSX
- c# - 将 WCF 服务请求参数更改为消息而不中断客户端
- python - 只获取 href beautifulsoup
- android - 弹出窗口使通知栏在 android 的全屏活动中可见
- flutter - 有没有办法在应用程序中打开 URL 而不是在浏览器中打开 URL?
- django - 我希望注册按钮在我注册时消失(在 django 模板中)'
- excel - 使用 VBA 插入新 Excel 行太多次导致错误 1004:Range 类的插入方法失败
- php - 如何按订阅者的电子邮件过滤订阅?
- angular - 如何从 Angular Material 更新 mat-table 数据
- azure - Microsoft.Azure.Management.Resourcemanager.Fluent 和 Microsoft.Azure.Management.Fluent nuget 包有什么区别?