最近公司项目中出现一个报错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…
// 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…
在运行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…
JSON.stringify()  我们很熟悉了,将一个对象转换为json形式的字符串. 但是如果你在浏览器控制台中输出 JSON.stringify(window). 如果期望输出一段文字, 可能会失望了. 事实上, 会输出结果如下: 错误信息很明显了, 对象中有循环引用. 解决方案如下: 参考链接:http://stackoverflow.com/questions/11616630/json-stringify-avoid-typeerror-converting-circular-str…
主要是因为对象的互相引用,怎么样才能造成对象的互相引用呢? 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…
别以为JSON.parse(JSON.stringify(data))做深拷贝无敌,对于以下这种情况,当你需要保留父级对象,即 对象存在循环引用,就会报错. var a = [ { "id":5, "pid":2, "categoryName":"搜索行为", }, { "id":6, "pid":3, "categoryName":"购买力",…
在ssh项目的applicaitonContext.xml中,少了一个双引号,打包成功(没报错),项目运行才发现. 加上少的双引号,解决了.…
=================实体类转JSON报错的解决办法============= 之前在springmvc的时候也报过这个错,原因以及springmvc中解决办法参考:https://www.cnblogs.com/qlqwjy/p/8722802.html 今天在springboot中同样遇到这个错. 错误分析:后台返回的数据格式是json的时候,格式化实体类报错,如下: @RequestMapping("doLogin") @ResponseBody public JSO…
windows server2008下如何更改MySQL数据库的目录的帖子已经很多了,这里简单介绍一个步骤,如果不成功请先查看其它帖子. 更改默认的mysql数据库目录 将 C:\Documents and Settings\All Users\Application Data\MySQL\MySQL Server 5.1\data 改到 D:\MysqlData . 建立文件夹 D:\MysqlData . 停止 mysql 服务,将 "C:\Documents and Settings\Al…