问题
I want to create offline an alphabet app for children using React-Native, and I want to ask you what is the best way to store data about each letter, for example: letter ID, letter NAME, letter IMG_SRC etc. I thought about using JSON, but as well decided to ask you about it. May be there's a better way. I'll be very happy if you share your own experience with me)
回答1:
The easiest way to store offline data is using the AsyncStorage, it's basically a key value storage, super easy to use. You can save json in there or any other text, for example:
AsyncStorage.setItem('data', JSON.stringify([{id: 1, name: 'a', src: ''}]));
Then, later on, you can get that data like this:
AsyncStorage.getItem('data', (err, result) => {
console.log(JSON.parse(result));
});
For simple apps, this is more than enough
来源:https://stackoverflow.com/questions/48571223/keep-data-in-offline-app-react-native