Receiving object as string
This question already has an answer here:
localStorage
stores strings. If you try to save an object, it will first call toString()
, resulting in "[object Object]"
.
You're better off saving it as JSON:
localStorage.setItem( 'apogeLiveLobbyData', JSON.stringify(tokenData.lobbyData));
and retrieving it that way, too
lobby : JSON.parse( localStorage.getItem('apogeLiveLobbyData') )
You can not store an object into local storage since it holds strings. So you need to make it a string to store and than parse it to get it back to an object.
JSON.stringify()
localStorage.setItem('apogeLiveLobbyData', JSON.stringify(tokenData.lobbyData));
JSON.parse()
var data = JSON.parse(localStorage.getItem('apogeLiveLobbyData'));
链接地址: http://www.djcxy.com/p/27944.html
下一篇: 以字符串形式接收对象