【发布时间】:2018-01-25 00:51:43
【问题描述】:
我正在处理类似文件树的对象:
var object = {
'name':'foo',
'contains': {'thisObject': object,'parentObject': /* the object that contains the current object*/, 'foo':'bar'},
'parent': /* the object that contains the current object*/
}
它可能看起来有点奇怪,但它看起来是有原因的。
这是用户决定的,所以它可以像这样结束:
object.contains["foo"].contains["bar"].contains["biz"].contains["frt"]...
我需要以某种方式将其保存到用户计算机。现在,我正在使用 localStorage 和 JSON.stringify()。但是这样,JSON 在循环结构错误上失败。
如何在保持循环结构的同时保存它? 有没有比 localStorage/JSON 更好的方法?
【问题讨论】:
标签: javascript json local-storage circular-reference