json - 如何将响应 json 数据的值保存到 AsyncStorage?
问题描述
constructor(props) {
super(props)
this.state = {
UserEmail: '',
UserPassword: ''
}
}
UserLoginFunction = () => {
const { UserEmail } = this.state;
const { UserPassword } = this.state;
axios.post(`Login`, {
username: this.state.UserEmail,
password: this.state.UserPassword
})
.then(response => {
console.log(response.data);
})
.catch((error) => {
console.error(error);
});
}
回复:
[{"return_type":"true","role_id":"1","users_id":"1","manpower_id":"1","message":"Success"}]
解决方案
AsyncStorage 与字符串一起使用。您需要保存:
JSON.stringify(response.data)
在里面。
像这样的东西:
const data = JSON.stringify(response.data);
await AsyncStorage.setItem('key or any name you want', data);
推荐阅读
- out-of-memory - 如何在 jboss eap 生产服务器中监控 Java 堆内存使用情况
- java - 从数据库获取 URL 后的 URL 访问安全性及其在 java 文件中的角色
- java - 如何将 string(R.id.btn_0) 转换为 int 类型 - Espresso
- azure - Luis get intent API 没有向我发送正确的意图?
- javascript - JQuery 模块模式:单击切换功能无法使用
- java - 执行 hql 查询时出错
- google-chrome - Serenity BDD 不要删除浏览器内存
- r - R 语言:增强的 Dickey Fuller 测试的结果是什么意思?
- python - 如何关闭另一个班级的kivy pop?
- javascript - chrome控制台中是否有粘贴功能?