Reactjs Expo:React仅在手机上抛出JSON解析错误

Reactjs Expo:React仅在手机上抛出JSON解析错误,reactjs,react-native,expo,Reactjs,React Native,Expo,我有一个用户注册屏幕。当我在我的计算机上填写时,操作完成,没有任何故障;但是,当我在手机上的Expo应用程序上打开应用程序时,我在提交表单时出现此错误,并且没有任何信息发送到我的服务器: JSON解析错误:意外的标识符“丢失” 其余错误如下所示: * [native code]:null in parse - node_modules\react-native\node_modules\promise\setimmediate\core.js:37:13 in tryCallOne - node

我有一个用户注册屏幕。当我在我的计算机上填写时,操作完成,没有任何故障;但是,当我在手机上的Expo应用程序上打开应用程序时,我在提交表单时出现此错误,并且没有任何信息发送到我的服务器:

JSON解析错误:意外的标识符“丢失”

其余错误如下所示:

* [native code]:null in parse
- node_modules\react-native\node_modules\promise\setimmediate\core.js:37:13 in tryCallOne
- node_modules\react-native\node_modules\promise\setimmediate\core.js:123:24 in setImmediate$argument_0
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:130:14 in _callTimer
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:181:14 in _callImmediatesPass
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:441:30 in callImmediates
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:387:6 in __callImmediates
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:135:6 in __guard$argument_0
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:364:10 in __guard
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:134:4 in flushedQueue
* [native code]:null in flushedQueue
* [native code]:null in invokeCallbackAndReturnFlushedQueue
以下是生成错误的方法:

  saveData = () => {
    this.setState({ loading: true, disabled: true }, () => {
      fetch(url, {
        method: 'POST',
        headers: 
        {
          'Accept': 'application/json',
          'Content-Type': 'application/json'
        },
        body: JSON.stringify(
        {
          username: this.state.username,
          password: this.state.password,
          email: this.state.email
        })
      }).then((response => { return response.json(); })).then((responseJson) => {
        alert(responseJson);
        this.setState({ loading: false, disabled: false });
      }).catch((error) => {
        console.error(error);
        this.setState({ loading: false, disabled: false });
      })
    });
  }

我真的不知道从哪里开始弄清楚这个,因为它在我的电脑浏览器中运行得非常好。我手头上也没有任何其他设备可以试用。此错误显示在我的控制台中,但它不会显示在我浏览器的Metro Bundler窗口中,也不会显示在我的手机上。我在iOS 13和最新版本的Expo上运行iPhone8。有什么想法吗?

您可能没有得到预期的响应。尝试记录
response.text()
(也是一个承诺),你会看到它不是json,但可能是服务器错误。@brentvatne得到了日志,说出了这一点:
promise{U:0,“\U V:0,“\U W:null,”\U X:null,}
老实说,我不知道这是什么意思,但尽管如此,我还是无法想象这是一个服务器错误,因为我在我的电脑浏览器中可以正常工作。但是,此日志是否指示其他系统错误?
response.text()
返回一个承诺。您必须使用
response.text()。然后(text=>console.log(text))
或使用
async/await
您可能没有得到预期的响应。尝试记录
response.text()
(也是一个承诺),你会看到它不是json,但可能是服务器错误。@brentvatne得到了日志,说出了这一点:
promise{U:0,“\U V:0,“\U W:null,”\U X:null,}
老实说,我不知道这是什么意思,但尽管如此,我还是无法想象这是一个服务器错误,因为我在我的电脑浏览器中可以正常工作。但是,此日志是否指示其他系统错误?
response.text()
返回一个承诺。您必须使用
response.text()。然后(text=>console.log(text))
或使用
async/await