I would like to know how to use Ionic Storage to store Json Object with Ionic 3. I am finding it difficult as there are no examples for the ionic 3 and i am stuck. Nothing on the net seems to be updated. A supporting example for Ionic Storage would be of great use. Thank you in advance.
1 Answer
Yes, you can store JSON objects in Ionic storage.
let your_json_object = { "name":"John", "age":30, "car":null };
// set a key/value
storage.set('my-json', your_json_object);
// to get a key/value pair
storage.get('my-json').then((val) => {
console.log('Your json is', val);
});
6 Comments
Tegar D Pratama
How to store JSON from api? example from here randomuser.me/api
Sampath
Just access your rest API using
HTTP and then store the result as shown above. What is the issue here?Tegar D Pratama
Ok i'll try. Sorry i'm new to ionic
Sampath
OK, sure. If you have any issue please let us know.
Sampath
Yes, you can. But I highly recommend using
Ionic Caching Service module if you need to work on the offline use case. Since it has a lot of features. ionicacademy.com/ionic-caching-service |