sessionStorage not storing original object

笑着哭i 提交于 2019-12-02 07:58:27

Try

sessionStorage.setItem('xyzObject', JSON.stringify(xyzObject);

And retrieve using:

  JSON.parse(sessionStorage.getItem('xyzObject'));

You cannot store an object in the sessionStorage or localStorage. The only possible method is to stringify the object and save that in sessionStorage and on receiving the object from sessionStorage you just parse the object to JSON.

var xyzObject = some_function();

sessionStorage.setItem("xyzObject",JSON.stringify(xyzObject));

var stringData = sessionStorage.getItem("xyzObject");

var obj = JSON.parse(stringData);

obj.some_other_function();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!