标题的值无法从 ReadablenativeMap 转换为字符串

新手上路,请多包涵

考虑:

 InsertDataToServer = () => {
  const { pinValue1 } = this.state;
  const { pinValue2 } = this.state;
  const { pinValue3 } = this.state;
  const { pinValue4 } = this.state;
  var String_3 = pinValue1.concat(" ", pinValue2);
  var String_4 = String_3.concat(" " , pinValue3);
  var String_5 = String_4.concat(" " , pinValue4);

  fetch("http://www.aonde.biz/mobile/doLogin.php", {
    method: "POST",
    headers: {
      Accept: "application/json",
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      "pin": 212,
    })
  })
    .then(response => response.json())
    .then(responseJson => {
      // Showing the response message coming from
      // the server after inserting records.
      Alert.alert(responseJson);
    })
    .catch(error => {
      console.error(error);
    });

在上面的代码中,当我传递“pin”参数 API 时,它显示了这个错误:

在图像中显示完整错误

我该如何解决这个问题?

原文由 Atul Tiwari 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 369
2 个回答

您可以简单地从 pin 中删除双引号。

 fetch("http://www.aonde.biz/mobile/doLogin.php", {
  method: "POST",
  headers: {
    Accept: "application/json",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    pin:212,
  })
})

原文由 Samitha Nanayakkara 发布,翻译遵循 CC BY-SA 4.0 许可协议

当代码从以下位置更改时,此错误已修复:

Alert.alert('Error:', error)

到:

Alert.alert('Error:', error.message)

原文由 Bill Zelenko 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题