Uncaught TypeError: Converting circular structure to JSON--JSON.stringify()

529 阅读1分钟

错误信息:

报错的原因在于:
在请求中传递的对象有一个循环引用

解决方案:

var cache = [];
var str = JSON.stringify(org, function(key, value) {
    if (typeof value === 'object' && value !== null) {
        if (cache.indexOf(value) !== -1) {
            // Circular reference found, discard key
            return;
        }
        // Store value in our collection
        cache.push(value);
    }
    return value;
});
cache = null; // Enable garbage collection

来源网址:blog.csdn.net/qq_36657997…