如何解决ReactNative中发送的“杰森解析错误:意外的EOF”错误?

时间:2019-04-02 11:22:36

标签: json api react-native fetch

因此,我正在开发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});
        });
    });
}

谢谢很多人!

0 个答案:

没有答案