简体   繁体   中英

Ionic Storage not outputing my stored JSON data correctly - Angular

I have something like the following:

        Storage.remove({key: 'somedata'}).then(r => {
          Storage.set({key: 'somedata', value: data}).then(g => {
            Storage.get({key : 'somedata'}).then((val) => {
              console.log('Your json is', val);
            });
          });
        });

I get data from my API in JSON from and try to store it.

When I then try to output the stored data in the console I get the following

图片示例

I am wondering how I can get the acctual data instead of it being object object

Thanks

Update - Picture of error with potential solution在此处输入图像描述

I think you don't need to remove

Storage.set(key, data).then(g => {
   Storage.get(key).then((val) => {
      console.log('Your json is', val);
   });
});

In my opinion, I think you can try this

Storage.remove({key: 'somedata'}).then(r => {
   Storage.set({key: 'somedata', value: JSON.stringify(data)}).then(g => {
      Storage.get({key : 'somedata'}).then((val) => {
          console.log('Your json is', JSON.parse(val));
      });
   });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM