在运行nodejs程序的时候报出以下的错误:

2017-11-20 17:44 +08:00: TypeError: Converting circular structure to JSON
at Object.stringify (native)
at stringify (/home/dev/backend/backcode/owner-backend/node_modules/express/lib/response.js:1075:12)
at ServerResponse.json (/home/dev/backend/backcode/owner-backend/node_modules/express/lib/response.js:249:14)
at /home/ubuntu/sample/index.js:728:10
at propagateAslWrapper (/usr/lib/node_modules/pm2/node_modules/async-listener/index.js:421:23)
at /usr/lib/node_modules/pm2/node_modules/async-listener/index.js:458:70

错误说明指的是对象存在循环引用,在将对象进行json序列化的时候就会报错。出现该问题的原因是在编写代码的时候没有注意到javascript的语法特性,或者说语法缺陷,也就是缺少块级作用域。

var obj  = {a:1, b:2};
var s = [];
var list = ['a','b', 'c','d'];
list.forEach(function(ele, i){
var obj = {};
obj[ele] = i;
s.push(obj);
});
obj.list = s;
JSON.stringify(obj)

Javascript报错Converting circular structure to JSON 错误排解的更多相关文章

  1. Javascript报错Converting circular structure to JSON

    主要是因为对象的互相引用,怎么样才能造成对象的互相引用呢? var a = {}; var b = {}; a.b = b; b.a = a; 怎么解决,反正我试了很多,最后选择深度clone thi ...

  2. 项目中遇到Uncaught TypeError: Converting circular structure to JSON报错问题

    最近公司项目中出现一个报错Uncaught TypeError: Converting circular structure to JSON,,根据上述报错可以知道代码是运行到JSON.stringi ...

  3. Object.stringify 循环引用 bug & TypeError: Converting circular structure to JSON

    Object.stringify 循环引用 bug & TypeError: Converting circular structure to JSON var obj = { a: &quo ...

  4. JSON.stringify方法报错:Converting circular structure to JSON

    别以为JSON.parse(JSON.stringify(data))做深拷贝无敌,对于以下这种情况,当你需要保留父级对象,即 对象存在循环引用,就会报错. var a = [ { "id& ...

  5. JSON.stringify出现 "Converting circular structure to JSON"

    JSON.stringify()  我们很熟悉了,将一个对象转换为json形式的字符串. 但是如果你在浏览器控制台中输出 JSON.stringify(window). 如果期望输出一段文字, 可能会 ...

  6. 处理TypeError: Converting circular structure to JSON

    // Demo: Circular reference var o = {}; o.o = o; // Note: cache should not be re-used by repeated ca ...

  7. python中读取json文件报错,TypeError:the Json object must be str, bytes or bytearray,not ‘TextIOWrapper’

    利用python中的json读取json文件时,因为错误使用了相应的方法导致报错:TypeError:the Json object must be str, bytes or bytearray,n ...

  8. ArcGIS Runtime SDK for WPF之SimpleRenderer无法添加、报错“图形符号无法序列化为 JSON”

    ArcGIS Runtime SDK for WPF之SimpleRenderer无法添加.报错“图形符号无法序列化为 JSON” 在上一篇博文中如果在 esri:Map 里面是否设置了的UseAcc ...

  9. npm install 报错 error Unexpected end of JSON input while parsing near '...sShrinkwrap":false,"d' 解决办法

    npm install 报错 : error Unexpected end of JSON input while parsing near '...sShrinkwrap":false,& ...

随机推荐

  1. PHP.14-图片处理类

    图片处理类 test.php <?php include "images.class.php"; $image=new Image("./images/" ...

  2. Keil如何生成bin文件【Keil生成Bin文件的方法】

    使用过Keil的同鞋都知道,现在Keil中默认可以输出.axf的调试文件和可以通过钩选输出的.hex可执行文件,没有bin(二进制)文件的输出选项.可是偏偏某些时候需要或者习惯性的使用.bin文件来进 ...

  3. miniui IE对省略号即text-overflow:ellipsis显示不一样的问题

    做miniui项目中发现,IE对文本以英文或数字结尾的是英文的省略号,以汉字结尾的就是中文的省略号.只要将字体变为统一宋体即可解决.即 .mini-grid-cell-inner    {       ...

  4. loj2100 「TJOI2015」线性代数

    先推公式,推出个这,然后因为是 \(0/1\) 矩阵,选一个有损耗,两个一组有加成,就想到了最大权闭合子图,(飞行计划问题) #include <iostream> #include &l ...

  5. Fiddler - 使用教程

    1.断点调试,修改请求表单和响应数据 命令介绍: bpu在请求开始时中断,bpafter在响应到达时中断,bps在特定http状态码时中断,bpv/bpm在特定请求method时中断. bpu m.t ...

  6. 《Cracking the Coding Interview》——第16章:线程与锁——题目5

    2014-04-27 20:16 题目:假设一个类Foo有三个公有的成员方法first().second().third().请用锁的方法来控制调用行为,使得他们的执行循序总是遵从first.seco ...

  7. APP测试工程师面试题:之一

    第六题主要流程:编写计划 → 测试用例 → 评审用例 → 执行用例 → 写BUG →测修复情况 → 上线

  8. 搭建 MongoDB分片(sharding) / 分区 / 集群环境

    1. 安装 MongoDB 三台机器 关闭防火墙 systemctl stop firewalld.service 192.168.252.121 192.168.252.122 192.168.25 ...

  9. MVC学习笔记----@Helper标签(HelperMethod方法)和HtmlExtesion扩展

    1,HtmlHelper扩展 http://www.cnblogs.com/willick/p/3428413.html http://www.cnblogs.com/zengdingding/p/5 ...

  10. PTA 11-散列3 QQ帐户的申请与登陆 (25分)

    题目地址 https://pta.patest.cn/pta/test/15/exam/4/question/723 5-15 QQ帐户的申请与登陆   (25分) 实现QQ新帐户申请和老帐户登陆的简 ...