因此,我正在开发ReactNative App,并创建一个新用户,我正在使用该用户提供的信息创建一个Json,然后将其发送到PhP文件中,该文件将解析Json收到的内容进行存储。数据库。 但是问题是我的JSON无法发送,并且我有一个宏伟的红屏“ JSON解析错误:意外的EOF” 如果你们有我的解决方案,经过漫长的调试夜晚,那就太好了。
这是我的提取代码:
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});
});
});
}
谢谢很多人!