Results 1 to 1 of 1

Thread: JSON encode objects with circular references

  1. #1
    Sencha Premium Member krause's Avatar
    Join Date
    Jun 2008

    Question JSON encode objects with circular references

    I found this antique thread and this other regarding this issues but in the first case Jack says "there's no easy way to detect" a circular reference while the other thread deals more with the fact that someone was trying to encode an object that shouldn't.
    In my case the objects I'm trying to serialize are pure data objects (i.e. not Ext components or Records or stuff with behaviour), but they do have circular references.


    var a = {name : 'a'};
    var b = {name : 'b', a : a};
    a.b = b;
    In this case, when I call
    I get an "InternalError: too much recursion".

    I patched the encode function to keep track of the objects that have already bee encoded so that if I detect the same object again (using === ) I just skip it (setting the property value to null).

    It seems to work fine, at least for simple cases, but given the very few post regarding this issue I was wondering if there is something fundamentally flawed in having circular references in the first place.

    Last edited by krause; 23 Sep 2010 at 1:27 PM. Reason: Error in example.

Similar Threads

  1. json encode/decode
    By humpdi in forum Ext 1.x: Help & Discussion
    Replies: 7
    Last Post: 19 Jun 2009, 12:07 AM
  2. Keeping references to lazily rendered objects
    By evant in forum Community Discussion
    Replies: 28
    Last Post: 10 Oct 2008, 12:20 AM
  3. JSON.encode
    By larsa in forum Ext 2.x: Help & Discussion
    Replies: 4
    Last Post: 26 Aug 2008, 2:03 PM
  4. JSON encode bug
    By harish in forum Ext 1.x: Bugs
    Replies: 6
    Last Post: 8 Feb 2007, 4:37 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts