I trief to use the localStorage object in Phonegap, but instead of getting an object, the getItem only recei开发者_C百科ves 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?
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.
精彩评论