Busca lo que quieras

Solución de error de JSON.stringify Converting circular structure to JSON

Todo esto gracias a stackoverflow y sus usuarios maravillosos que comparten la información

Para solucionar esto... podemos hacer lo siguiente:

No utilizar la función JSON.stringify SINO JSON.pruned

Para esto hay que hacer dos pasos:

PASO NO. 1:

JSON.pruned no existe realmente, toca primero agregarla... de manera que...

a. Abrimos la consola del navegador....
b. Ejecutamos lo siguiente que esta en negrita:

// JSON.pruned : a function to stringify any object without overflow
// example : var json = JSON.pruned({a:'e', c:[1,2,{d:{e:42, f:'deep'}}]})
// two additional optional parameters :
//   - the maximal depth (default : 6)
//   - the maximal length of arrays (default : 50)
// GitHub : https://github.com/Canop/JSON.prune
// This is based on Douglas Crockford's code ( https://github.com/douglascrockford/JSON-js/blob/master/json2.js )
(function () {
    'use strict';

    var DEFAULT_MAX_DEPTH = 6;
    var DEFAULT_ARRAY_MAX_LENGTH = 50;
    var seen; // Same variable used for all stringifications

    Date.prototype.toPrunedJSON = Date.prototype.toJSON;
    String.prototype.toPrunedJSON = String.prototype.toJSON;

    var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
        escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
        meta = {    // table of character substitutions
            '\b': '\\b',
            '\t': '\\t',
            '\n': '\\n',
            '\f': '\\f',
            '\r': '\\r',
            '"' : '\\"',
            '\\': '\\\\'
        };

    function quote(string) {
        escapable.lastIndex = 0;
        return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
            var c = meta[a];
            return typeof c === 'string'
                ? c
                : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
        }) + '"' : '"' + string + '"';
    }

    function str(key, holder, depthDecr, arrayMaxLength) {
        var i,          // The loop counter.
            k,          // The member key.
            v,          // The member value.
            length,
            partial,
            value = holder[key];
        if (value && typeof value === 'object' && typeof value.toPrunedJSON === 'function') {
            value = value.toPrunedJSON(key);
        }

        switch (typeof value) {
        case 'string':
            return quote(value);
        case 'number':
            return isFinite(value) ? String(value) : 'null';
        case 'boolean':
        case 'null':
            return String(value);
        case 'object':
            if (!value) {
                return 'null';
            }
            if (depthDecr<=0 || seen.indexOf(value)!==-1) {
                return '"-pruned-"';
            }
            seen.push(value);
            partial = [];
            if (Object.prototype.toString.apply(value) === '[object Array]') {
                length = Math.min(value.length, arrayMaxLength);
                for (i = 0; i < length; i += 1) {
                    partial[i] = str(i, value, depthDecr-1, arrayMaxLength) || 'null';
                }
                v = partial.length === 0
                    ? '[]'
                    : '[' + partial.join(',') + ']';
                return v;
            }
            for (k in value) {
                if (Object.prototype.hasOwnProperty.call(value, k)) {
                    try {
                        v = str(k, value, depthDecr-1, arrayMaxLength);
                        if (v) partial.push(quote(k) + ':' + v);
                    } catch (e) { 
                        // this try/catch due to some "Accessing selectionEnd on an input element that cannot have a selection." on Chrome
                    }
                }
            }
            v = partial.length === 0
                ? '{}'
                : '{' + partial.join(',') + '}';
            return v;
        }
    }

    JSON.pruned = function (value, depthDecr, arrayMaxLength) {
        seen = [];
        depthDecr = depthDecr || DEFAULT_MAX_DEPTH;
        arrayMaxLength = arrayMaxLength || DEFAULT_ARRAY_MAX_LENGTH;
        return str('', {'': value}, depthDecr, arrayMaxLength);
    };

}());

PASO NO. 2

Ya podemos ejecutar nuestra funcion normalmente

JSON.pruned(miobjetoaserializar)

PASO NO. 3 EXTRA
Si queremos ver nuestro JSON BONITO.... podemos ir a la url:

https://www.jsoneditoronline.org/

Y hay podemos pasar toda esa serializacion y verla de manera organizada.

Espero les sirva.

Sean felices! :) Y siéntanse libres de opinar ;)

2 comentarios:

Palabras Clave

.NET (93) AJAX (2) ajaxcontroltoolkit (2) Algoritmos (1) android (1) Angular (1) Arrays (1) AS2 o ActionScript 2.0 (1) AS3 o ActionScript 3.0 (64) ASP (7) ASP.NET (3) Azure (1) Azure DevOps (2) Backup (2) Batch (4) blogger (1) Browser Support (2) C# (53) Charts (1) Chorme extensions (1) Chrome (3) cmd (18) código postal (1) Colombia tips (1) command (1) Conexion remota (1) Controles Web .NET (24) Cookies (1) cordova (1) CSS (14) CSV (5) Cufon (1) DateTime (2) deployment (2) Desarrollo movil (2) Desarrollo web (5) Diseño (4) DNN o DotNetNuke (5) docker (1) Encuestas (1) Entity Framework (1) Error (1) Eval (2) Excel (4) Expresiones regulares (2) Facebook (14) fechas (1) Fiddler (1) FileUpload (1) Filezilla (1) Firefox (2) Flash (9) Fonts (3) FQL (1) frameworks (2) Futuro de la web (1) git (1) Google Code (13) Google Maps (4) hackintosh (3) hazard 10.6.2 (3) herramientas para developers (1) highchart (1) Hilos (2) Hosting Windows (18) HTML (38) HTML5 (6) IDE (1) IE (2) IE9 (1) IIS (13) imagenes (3) jasmine (2) java (1) jqgrid (2) Jquery y Javascript (90) jquery-ui (5) jQueryMobile (1) JSON (1) knockout (4) library (1) Link Interesantes (2) List (1) Macro (2) Matemáticas (2) Membership (6) Memoria (1) Mis Experiencias (3) momentjs (1) ms-dos (1) MSN (1) MVC (1) MVC4 (3) MySQL (2) node.js (4) Notepad++ (3) Notificaciones (1) ObjectDataSource (2) Online (2) Opinión (4) OSX (3) Parallels Plesk Panel (1) petapoco (1) PhantomJS (1) PHP (4) Porqué este blog (1) Powershell (1) Razor (3) Redes (2) REGEX (4) REST (1) SDK Android (1) Seguridad (1) SelectParameters (1) Selenium (2) sencha (3) sencha cmd (2) SEO (1) SMTP (2) Software útil (8) Solución (1) Soporte (1) SQL (15) SQL Server (58) SQLite (2) Store Procedures (20) String (5) Testing Code (2) texto (2) tips de datos (1) tips de desarrollo (1) TutoFaceAS3 (4) TutoProAS3 (4) Tutoriales (7) Tweenlite effects (3) Últimas noticias (1) unit testing (1) usb (1) VBA (1) Video (1) virus (1) Web API (2) Web Browsers (1) Web Forms (7) web.config (1) Webmaster (8) Webmatrix (1) webrole (1) webservices (1) webstorm (1) Win Forms (5) Windows (21) Windows 7 (1) Windows 8 (1) XML (2) Youtube API (2)