admin管理员组文章数量:1192947
I want to persist some JSON information in browser. Depending on user interaction with the application, I want to store 5-6 different JSON object into memory. What options I have to achieve this? Please suggest any library or plugin using which I can persist information in the browser.
Thanks
I want to persist some JSON information in browser. Depending on user interaction with the application, I want to store 5-6 different JSON object into memory. What options I have to achieve this? Please suggest any library or plugin using which I can persist information in the browser.
Thanks
Share Improve this question asked Sep 20, 2013 at 9:18 SharpCoderSharpCoder 19.2k43 gold badges162 silver badges258 bronze badges3 Answers
Reset to default 14To add to the solutions given, I'd also want to add a reference link Storing Objects in HTML5 localStorage where this question is discussed nicely.
Below is the code
var testObject = { 'one': 1, 'two': 2, 'three': 3 };
// Put the object into storage
localStorage.setItem('testObject', JSON.stringify(testObject));
// Retrieve the object from storage
var retrievedObject = localStorage.getItem('testObject');
console.log('retrievedObject: ', JSON.parse(retrievedObject));
Courtesy: CMS
You can use HTML5 storage which gives you both local and session storage.
Local storage persists it in a local cache and can therefore be accessed again in the future, despite the browser being closed.
Session storage will only store the information for that particular session and will be wiped once the session ends.
e.g.
//get item from storage
var foo = localStorage["bar"];
//set item in storage.
localStorage["bar"] = foo;
Use the HTML5 storage. This stores persistent data.
You can access it with localStorage["key"]
.
本文标签: javascriptStoring JSON data in browser memoryStack Overflow
版权声明:本文标题:javascript - Storing JSON data in browser memory - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738436256a2086695.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论