关于JSON.stringify循环引用问题的解决

453 阅读1分钟

最近在转将对象转换成string,往storage里面存的时候,报错: TypeError: Converting circular structure to JSON。

这个的问题是因为循环引用导致的。那怎么解决呢?

可以用cycle.js,详情地址:github.com/douglascroc…

在vue项目的或react项目引入js,就可以了使用了。

` let _json = {a:111}; _json.x = _json;

let newObj = JSON.decycle(_json);

JSON.stringify(newObj); //这样即可

`