在运行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…
主要是因为对象的互相引用,怎么样才能造成对象的互相引用呢? var a = {}; var b = {}; a.b = b; b.a = a; 怎么解决,反正我试了很多,最后选择深度clone this.planAddParams['actionInfoList'] = this.deepClone(this.actionInfoList) deepClone (source) { if (!source || typeof source !== 'object') { throw new Er…
最近公司项目中出现一个报错Uncaught TypeError: Converting circular structure to JSON,,根据上述报错可以知道代码是运行到JSON.stringify时,抛出了这个错误,代码中使用JSON.parse跟JSON.stringify来实现便捷深复制,网上查询了一圈,原来是要深复制的对象被循环引用,什么意思呢?如下所示 我们声明两个对象,然后把第一个对象赋值给第二个对象里面的一个属性,把第二个对象赋值给第一个对象里的某个属性,此时就是循环引用,这…
Object.stringify 循环引用 bug & TypeError: Converting circular structure to JSON var obj = { a: "foo", }; // undefined obj; //{a: "foo"} obj.b = obj; // {a: "foo", b: {-}} JSON.stringify(obj); /* VM205:1 Uncaught TypeError: C…
别以为JSON.parse(JSON.stringify(data))做深拷贝无敌,对于以下这种情况,当你需要保留父级对象,即 对象存在循环引用,就会报错. var a = [ { "id":5, "pid":2, "categoryName":"搜索行为", }, { "id":6, "pid":3, "categoryName":"购买力",…
JSON.stringify()  我们很熟悉了,将一个对象转换为json形式的字符串. 但是如果你在浏览器控制台中输出 JSON.stringify(window). 如果期望输出一段文字, 可能会失望了. 事实上, 会输出结果如下: 错误信息很明显了, 对象中有循环引用. 解决方案如下: 参考链接:http://stackoverflow.com/questions/11616630/json-stringify-avoid-typeerror-converting-circular-str…
// Demo: Circular reference var o = {}; o.o = o; // Note: cache should not be re-used by repeated calls to JSON.stringify. var cache = []; JSON.stringify(o, function(key, value) { if (typeof value === 'object' && value !== null) { if (cache.indexO…
利用python中的json读取json文件时,因为错误使用了相应的方法导致报错:TypeError:the Json object must be str, bytes or bytearray,not‘TextIOWrapper’. 解决方法: 首先要弄明白json有四个方法:dumps和loads.dump和load.其中,dumps和loads是在内存中转换(python对象和json字符串之间的转换),而dump和load则是对应于文件的处理. 出现这个错误的原因是自己用了loads方…
ArcGIS Runtime SDK for WPF之SimpleRenderer无法添加.报错“图形符号无法序列化为 JSON” 在上一篇博文中如果在 esri:Map 里面是否设置了的UseAcceleratedDisplay属性 ,如果设置 UseAcceleratedDisplay="false" 那么运行的时候总会报错“图形符号无法序列化为 JSON” 改为true完美解决问题…
npm install 报错 : error Unexpected end of JSON input while parsing near '...sShrinkwrap":false,"d' 解决办法: 运行如下命令 npm cache clean --force…