web-dev-qa-db-ja.com

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

上記のコードでピンパラメータAPIを渡すと、このエラーが表示されます。ありがとうin image show full erro この問題を解決する方法を教えてください。

2
Atul Tiwari

pinから二重引用符を削除するだけです。

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

alert.alert(responseJson);このように文字列化する必要があります

Alert.alert(JSON.stringify(responseJson));

アラートはモバイルアプリのコンポーネントであるため、jsonがあることを示すコードを理解できない可能性があることに注意してください。それが機能しない場合は、responseJson.text()を使用してください。

1
Nicolas Silva

アラートにエラー全体ではなくerror.MESSAGEが表示されていることを確認してください。エラーとそのタイプによっては、原因となる可能性があります。

それが私の問題の原因でした。

0
Marlon Englemam

Alertメソッドにタイトルを追加すると、エラーが修正されました。ドキュメントでは、Alertメソッドの呼び出し中にAlertのタイトルを指定する必要があるためです。

0
Ömer