(@_@;)我是程序猿,我编程,我快乐,知识改变命运,技术成就梦想   oh yeah!合作VX "w6668263" 联系Email:ye583025823@126.com

Uncaught TypeError: Converting circular structure to JSON

 

在使用JSON.stringify方法去转化成字符串,会报错TypeError: Converting circular structure to JSON

原因: 对象中有对自身的循环引用;

 

解决方法:
下面的 json_str 就是JSON.stringify 转换后的字符串

 

var cache = [];
var json_str = JSON.stringify(json_data, function(key, value) {
    if (typeof value === 'object' && value !== null) {
        if (cache.indexOf(value) !== -1) {
            return;
        }
        cache.push(value);
    }
    return value;
});
cache = null;    //释放cache

参考:https://blog.csdn.net/g401946949/article/details/101757165

posted on 2022-10-10 09:47  一个草率的龙果果  阅读(628)  评论(0编辑  收藏  举报

导航