我在AsyncStorage.getItem上遇到问题。我有一个模块,即登录名,我需要在存储中设置该项目,得到结果后,下面有一条黄色消息,提示我有错误:java.lang.Double无法转换为java.lang.String我不知道错误在哪里。
我会告诉大家,我的功能是在存储中设置项目。
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);
});
}
答案 0 :(得分:0)
使用expires_in
强制在js端输入文字。我想这里是 AsyncStorage.setItem('authorization_code',access_token);
AsyncStorage.setItem('authorization_expiration',expires_in.toString());
AsyncStorage.setItem('authorization_type',token_type);
的浮点数,所以:
{{1}}
答案 1 :(得分:0)
此问题来自数据类型错误。一旦使用了异步存储,就必须仅存储字符串数据类型。如果您存储一个int,它将通过此错误。因此,您可以在源代码末尾使用.toString()
AsyncStorage.setItem('userId', response.data.dataset[0].id.toString());