在浏览器内存中存储JSON数据 [英] Storing JSON data in browser memory
本文介绍了在浏览器内存中存储JSON数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在浏览器中保留一些JSON信息.根据用户与应用程序的交互,我想将5-6个不同的JSON对象存储到内存中.我要实现此目的有哪些选择?请建议我可以用来在浏览器中保留信息的任何库或插件.
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.
谢谢
推荐答案
To 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.
下面是代码
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));
礼貌:CMS
这篇关于在浏览器内存中存储JSON数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文