react-native - 如何修复 java.lang.Double 在 React Native 中无法转换为 java.lang.String

标签 react-native

我对我的 AsyncStorage.getItem 有疑问。我有一个模块,它是登录,我需要在存储中设置项目,在我得到结果后,下面有一条黄色消息,我有错误:java.lang.Double cannot be cast to java.lang.String I不知道错误出在哪里。

Error

我将向你们展示我在存储中设置项目的功能。

     if(response.status == '200')
     {
          AsyncStorage.setItem('authorization_code',access_token);
          AsyncStorage.setItem('authorization_expiration',expires_in);
          AsyncStorage.setItem('authorization_type',token_type);

          //let token = AsyncStorage.getItem(JSON.stringify("authorization_code"));
           AsyncStorage.getItem('authorization_code', (err, result) => {
            alert(result);
          });

     }

最佳答案

使用toString()强制在 js 端输入。我想那是expires_in这里的浮点数,所以:

          AsyncStorage.setItem('authorization_code',access_token);
          AsyncStorage.setItem('authorization_expiration',expires_in.toString());
          AsyncStorage.setItem('authorization_type',token_type);

关于react-native - 如何修复 java.lang.Double 在 React Native 中无法转换为 java.lang.String,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56279308/

相关文章:

android - 由于Asyncstorage库中的警告,可以删除buildToolsVersion android studio吗?

react-native - 如何删除博览会 BarCodeScanner 中的多余空白

javascript - Uncaught Error : Minified React error #130

javascript - setTimeout 方法内的渲染组件不起作用

android - react native promise

React-Native TouchableHighlight onFocus 在 Android TV 中不起作用

javascript - 如何从多个 url 获取数据并将其保存在数组中(React Native)

react-native - react native : What is the best practice to use global variables throughout your whole application?

javascript - Easy-peasy useStoreActions 不会立即更新状态?

android - ART 库在 native react 中不起作用