JSON

Converting circular structure to JSON web开发学习笔记

字号+ 作者:H5之家 来源:H5之家 2015-10-04 14:31 我要评论( )

Converting circular structure to JSON 管理系统在firefox开发,目前要兼容google chrome 。。firefox 下一切正常运行,但是在google chrome下出现这个错误提示:Converting circular structure to JSON MiscUtils.clone = function(object) { return JSON.

Converting circular structure to JSON

管理系统在firefox开发,目前要兼容google chrome 。。firefox 下一切正常运行,但是在google chrome下出现这个错误提示:Converting circular structure to JSON

MiscUtils.clone = function(object) {
return JSON.parse(JSON.stringify(object)); //出现错误提示代码行
};

网络上关于这个错误的说明:

It means that the object you pass in the request (I guess it ispagedoc) has a circular reference, something like:

var a = {}; a.b = a;

JSON.stringifycannot convert structures like this.

N.B.: This would be the case with DOM nodes, which have circular references, even if they are not attached to the DOM tree. Each node has anownerDocumentwhich refers todocumentin most cases.documenthas a reference to the DOM tree at least throughdocument.bodyanddocument.body.ownerDocumentrefers back todocumentagain, which is onlyoneof multiple circular references in the DOM tree.

最后的解决方法:

MiscUtils.clone = function(object) {
return object;
};

该方法的功能是克隆一个对象,传过来的参数也是一个object类型,所以就没有必要先转成string ,然后再转成object类型。。

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
网友点评