1. #1
    Sencha User krause's Avatar
    Join Date
    Jun 2008
    Vote Rating
    krause is on a distinguished road


    Question JSON encode objects with circular references

    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

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..."