开发者

Phonegap localStorage returns the string "[object Object]" instead of the object

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 localStorageallows 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜