我对我的 AsyncStorage.getItem 有疑问。我有一个模块,它是登录,我需要在存储中设置项目,在我得到结果后,下面有一条黄色消息,我有错误:java.lang.Double cannot be cast to java.lang.String I不知道错误出在哪里。
我将向你们展示我在存储中设置项目的功能。
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/