POST fails with ReadableNativeMap cannot be cast to String error
11,489
Alert.alert receives an string, and what you're getting from the fetch response is internally a com.facebook.react.bridge.ReadableNativeMap
object (which is what the native implementation for fetch returns).
You can try:
Alert.alert(JSON.stringify(responseJson))
If you were using iOS you'll get a completely different error:
Exception '-[_NSFrozenDictionaryM length]: unrecognized selector ...
![Berke](https://lh4.googleusercontent.com/-FPzi7FjYpXI/AAAAAAAAAAI/AAAAAAAAAP4/t137pMNtP7g/photo.jpg?sz=256)
Comments
-
Berke almost 2 years
I'm working in
React Native
, I usePHP
for backend and when I use fetchPOST
request I get so strange error, and I dont know why it happens. I checked the url so it works no problem, also normalfetch()
is working withoutPOST
but when I try to post it happens. When I try it in local server fetchPOST
works.. but in server, I get this error :ERROR : com.facebook.react.bridge.ReadableNativeMap cannot be cast to java.lang.String
React native codes :
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); });
-
Berke about 6 yearsok i will check alert part of the code and change it and let you know .
-
Berke about 6 yearsI checked now it gives other error but inside of alert, so we fixed this one. new Error is : {"message":"",exception":"Symfony\\Component\\HttpKernel...
-
Berke about 6 yearsI Think its about Laravel / PHP part, so I need to fix there. then thank you again!