Search code examples
jsonangulartypescriptionic3ionic-storage

How to use Ionic Storage to store json object from api with ionic 3?


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.


Solution

  • 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);
      });