将 JSON 数据存储在浏览器内存中 [英] Storing JSON data in browser memory

查看:29
本文介绍了将 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.

谢谢

推荐答案

要添加到给出的解决方案,我还想添加一个参考链接 在 HTML5 localStorage 中存储对象 很好地讨论了这个问题.

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));

礼貌:内容管理系统

这篇关于将 JSON 数据存储在浏览器内存中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆