POST 失败,并出现 ReadableNativeMap 无法转换为字符串错误

Ber*_*rke 4 fetch react-native

我正在工作React Native,我用于PHP后端,当我使用 fetchPOST请求时,我收到了很奇怪的错误,我不知道为什么会发生。我检查了网址,所以它工作没有问题,也正常fetch()工作POST,但当我尝试发布它时发生。当我在本地服务器获取工作中尝试它时POST..但是在服务器中,我收到此错误:

错误:com.facebook.react.bridge.ReadableNativeMap 无法转换为 java.lang.String

反应本机代码:

fetch('http://xxx/react_test1', {
  method: 'POST',
  headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    name: inputName,
    email: inputEmail,
    phone: inputPhone
  }),
}).then((response) => response.json())
  .then((responseJson) => {
    Alert.alert(responseJson);
  }).catch((error) => {
  alert(error);
});
Run Code Online (Sandbox Code Playgroud)

ely*_*ado 7

Alert.alert 接收一个字符串,并且从 fetch 响应中获取的内容在内部是一个com.facebook.react.bridge.ReadableNativeMap对象(这是 fetch 的本机实现返回的对象)。你可以试试:

Alert.alert(JSON.stringify(responseJson))
Run Code Online (Sandbox Code Playgroud)

如果您使用的是 iOS,您会收到完全不同的错误:

Exception '-[_NSFrozenDictionaryM length]: unrecognized selector  ...
Run Code Online (Sandbox Code Playgroud)