Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
590 views
in Technique[技术] by (71.8m points)

fetch - com.facebook.react.bridge.ReadableNativeMap cannot be cast to java.lang.Double

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.

Error : com.facebook.react.bridge.ReadableNativeMap cannot be cast to java.lang.Double

The response coming from the service is as below :

{
    "status": 1,
    "data": {
        "id": "551",
        "first_name": "sssss",
        "last_name": "lastname",
        "email": "[email protected]",
        "username": "sssss",
        "password": "e10adc83e",
        "photo": "",
        "birthdate": "1963-02-13",
        "gender": "",
        "token": "1234567890",
        "device_type": "2"
    },
    "message": "Successful Login"
}

What might be the issue ??

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...