I trief to use the localStorage object in Phonegap, but instead of getting an object, the getItem only receives a string "[object Object]"
:
var storage = window.localStorage;
storage.setItem('test',{'name':'mark','greeting':'Hello'});
console.log(storage.getItem('test'));
In the console of Google chrome it says:
[object Object]
The output of "console.log(storage)" is the following:
Storage ... test: "[object Object]"
If I try to access a property of the object it just says "undefined":
storage.getItem('test').name
Any ideas how to get this to work?
localStorage is a read-only property that returns a reference to the local storage object used to store data that is only accessible to the origin that created it.
LocalStorage is a key/value datastore that's available on a user's browser. Like cookies, LocalStorage can only store string data for its keys and values.
The getItem() method returns value of the specified Storage Object item. The getItem() method belongs to the Storage Object, which can be either a localStorage object or a sessionStorage object.
HTML5 localStorage
allows you to store strings only.
You'll have to perform a JSON.stringify
when you store your object, and JSON.parse
when you retrieve it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With