com.facebook.react.bridge.ReadableNativeMap无法转换为java.lang.Double [英] com.facebook.react.bridge.ReadableNativeMap cannot be cast to java.lang.Double
问题描述
am使用React的fetch()方法登录到我的服务.到目前为止,我已经完成了以下操作,您可以检查一下我的东西:
am using React's fetch() method to login in to my service. So far I have done as below, you can check out my stuffs :
_callApiForLogin = () => {
ToastAndroid.show('Logging In...', ToastAndroid.SHORT);
let data = new FormData();
data.append('username', "sssss");
data.append('password', "123456");
data.append('device_token', "hjkhjkhjkkksdkjhkjhksdsfs");
data.append('device_type', "2");
fetch('https://612.33.196.54/~yes/master/api/web/login', {
method: 'POST',
body: data,
}).then((response) => response.json())
.then((responseJson) => {
ToastAndroid.show('Logging In...', responseJson);
if (responseJson.status === '1') {
ToastAndroid.show('Logging Successful' + responseJson, ToastAndroid.SHORT);
}
return responseJson.status;
})
.catch((error) => {
console.error(error);
});
}
但是,响应时低于错误.
But, getting below error in response.
错误:com.facebook.react.bridge.ReadableNativeMap无法转换为java.lang.Double
来自服务的响应如下:
{
"status": 1,
"data": {
"id": "551",
"first_name": "sssss",
"last_name": "lastname",
"email": "ja@gmail.com",
"username": "sssss",
"password": "e10adc83e",
"photo": "",
"birthdate": "1963-02-13",
"gender": "",
"token": "1234567890",
"device_type": "2"
},
"message": "Successful Login"
}
可能是什么问题?
推荐答案
您正在使用 React Native Module
来显示 Toast
,即 ToastAndroid
因此您的错误 com.facebook.react.bridge.ReadableNativeMap .如此处所述的 show()
方法接受转换为双精度的 duration
作为其第二个参数,在这种情况下,您传递的是 responseJson
这是一个对象,因此无法将其转换为双精度型.
You are using a React Native Module
to show the Toast
i.e. ToastAndroid
hence com.facebook.react.bridge.ReadableNativeMap in your error. The show()
method as described here accepts a duration
which is converted into a double, as its second argument, in this case, you are passing responseJson
which is an object thus it cannot be cast to a double.
这篇关于com.facebook.react.bridge.ReadableNativeMap无法转换为java.lang.Double的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!