Phonegap localStorage 返回字符串“[object Object]”而不是对象
我尝试在 Phonegap 中使用 localStorage 对象,但 getItem 不是获取对象,而是只接收字符串 "[object Object]"
:
var storage = window.localStorage;
storage.setItem('test',{'name':'mark','greeting':'Hello'});
console.log(storage.getItem('test'));
在 Google chrome 的控制台中,它显示:
[object Object]
“的输出console.log(storage)”如下:
Storage ... test: "[object Object]"
如果我尝试访问对象的属性,它只会说“未定义”:
storage.getItem('test').name
有什么想法如何让它工作吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
HTML5
localStorage
允许您存储仅字符串。存储对象时必须执行 JSON.stringify,检索对象时必须执行 JSON.parse。
HTML5
localStorage
allows you to store strings only.You'll have to perform a
JSON.stringify
when you store your object, andJSON.parse
when you retrieve it.