标题的值不能从ReadablenativeMap强制转换为字符串

时间:2018-10-25 15:08:47

标签: android ios reactjs react-native

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 response message coming from server after inserting records.
    Alert.alert(responseJson);
  })
  .catch(error => {
    console.error(error);
  });

在上面的代码中,当我通过引脚参数API时显示此错误。谢谢 in image show full erro,请给出一些解决此问题的方法。

6 个答案:

答案 0 :(得分:7)

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

Alert.alert('Error:', error)

收件人:

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

答案 1 :(得分:0)

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

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

答案 2 :(得分:0)

在您的Alert.alert(responseJson);中;您需要像这样将其字符串化

app.get('/get-pathways-with-partner/', (req, res) => {
    let { partnerList } = req.query;
});

请记住,警报是移动应用程序中的一个组件,因此它可能无法理解显示有json的代码,如果不起作用,请使用responseJson.text()

答案 3 :(得分:0)

Alert 方法中添加标题时,该错误已修复,因为在文档中,必须在调用Alert方法时给出Alert的标题

答案 4 :(得分:0)

确保您的警报显示的是error.MESSAGE,而不是整个错误。可能是由于错误及其类型所致!

那是我问题的原因。

答案 5 :(得分:-1)

我遇到这个错误是因为我安装了一个需要我再次编译应用程序的库,而我没有编译它。

再次编译后一切正常。

相关问题