将圆形结构转换为JSON - 以任何方式找到它抱怨的字段? [英] Converting circular structure to JSON -- Any way to find what field it is complaining about?

查看:180
本文介绍了将圆形结构转换为JSON - 以任何方式找到它抱怨的字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Chrome中对一个对象进行字符串化(...),并且尽管(据我所知)没有这样的结构存在,但我仍然不断收到将循环结构转换为JSON消息。 / p>

我已经完成了十多次代码,无法找到任何循环引用。有没有什么办法让Chrome告诉我除了这个痛苦无用的错误信息之外还有什么讽刺?

解决方案

太明显了。在写这篇文章的时候,我不知道你已经试过了什么。



insert

  console.log(对象); 

将您的对象替换为您要传递给的对象 JSON.stringify ()



JSON.stringify 调用之前插入此行



,然后在控制台日志(shift控件J)中查找该对象。在控制台日志中,对象将被标记为一个>符号,可以通过单击符号将其展开到字段。



它抱怨一个指向对象的对象本身,就像这样的对象:

  A = []; 
A [0] = A;
JSON.stringify(A); //循环错误


I'm trying to stringify(...) an object in Chrome, and I keep getting a "Converting circular structure to JSON" message, despite the fact that (as far as I know) no such structure exists.

I've been over the code a dozen times and can't find any circular references whatsoever. Is there any way to get Chrome to tell me what it's bitching about beyond this painfully useless error message?

解决方案

Pardon me if this is too obvious. At the time of writing, I dont know what you have tried.

insert

console.log(the object); 

replacing 'the object' with the object you are passing to JSON.stringify()

insert this line before the JSON.stringify call

and look in the console log (shift control J) for the object. In the console log the object will be tagged with a ">" symbol which can be clicked to expand to the fields.

It is complaining about an object that has pointers into itself, like this kind of object:

A = [];
A[0] = A; 
JSON.stringify(A); // circular error

这篇关于将圆形结构转换为JSON - 以任何方式找到它抱怨的字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆