nodejs 循环引用JSON序列化错误的解决办法:TypeError: Converting circular structure to JSON

2017-07-16 20:20:08

nodejs 循环引用JSON序列化错误的解决办法:TypeError: Converting circular structure to JSON

可以 使用 util.inspect 代替 JSON.stringify

var util = require("util")var a = {};
a.b = a;
a.c = "123"; 
// console.log(JSON.stringify(a)); // 报错console.log(util.inspect(a,{depth:null})); //depth:null 展开全部层级12345671234567

如上代码输出结果

{ b: [Circular], c: '123' }


  • 2017-12-05 22:30:02

    php7.0升级php7.2

    看电脑上的教程要备份7.0配置文件以及扩展啥的,我感觉不如卸载干净重新安装

  • 2017-12-06 09:35:10

    分页优化的四种方式

    在大数据量的情况下,原本很简单的分页如果没有处理好,你会发现分页的请求会消耗你大量的数据库时间。如果你遇到了这个问题,文章给了你几个很好的解决的方案。当然,初学者若能看完这篇文章,那么它会指导你写出更具有扩展性的分页代码。