简体   繁体   English

如何在本机反应的异步存储中设置 object 数组

[英]How to set array of object inside async storage in react native

I am trying to set array of object inside async storage but I did not set it.我正在尝试在异步存储中设置 object 数组,但我没有设置它。 Could someone please help me how to achieve this.有人可以帮助我如何实现这一目标。 Thanks谢谢

Code代码

  let joined = this.state.product.concat(product);
    this.props.setNotification(joined);
    AsyncStorage.setItem("count", joined);

The easiest way is to stringify the array and store it最简单的方法是将数组字符串化并存储

AsyncStorage.setItem('count', JSON.stringify(joined));

You will have to parse the string when you retrieve it检索字符串时必须对其进行解析

const storedArray = await  AsyncStorage.getItem('count');
const array = JSON.parse(storedArray)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将多个项目推送到一个数组中并在 React Native 中加载到异步存储中? - How to push multiple items into an array and load into async storage in react native? React Native,使用异步存储在渲染中设置和获取相同的值 - React Native, Using Async Storage to Set and Get same Value in Render 反应本地异步存储不起作用 - react native Async Storage not working 如何在 object 中渲染对象数组? - How to render array of objects inside an object react native? 如何在 react-native 中写入异步存储值返回 function - how to write async storage value return function in react-native 如果我在对象中有一个数组并且该对象在一个大数组中,我该如何更新 React Native 状态? - How can I update the React Native state if I have an array inside an object and the object is inside in a big array? @react-native-async-storage/async-storage@npmreplace with @react-native-community/async-storage - @react-native-async-storage/async-storage@npmreplace with @react-native-community/async-storage React-Native异步Array.map = undefined不是Object - React-Native async Array.map = undefined is not an Object react-native 异步存储不保存并且没有错误 - react-native async storage is not saving and no errors 在异步存储 React Native 中添加新数据 - Add new data in Async Storage React Native
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM