序列化包含循環對象值的對象 - Serializing object that contains cyclic object value

問題:

I have an object (parse tree) that contains child nodes which are references to other nodes.我有一個對象(解析樹),其中包含對其他節點的引用的子節點。

I'd like to serialize this object, using JSON.stringify() , but I get我想序列化這個對象,使用JSON.stringify() ,但我得到

TypeError: cyclic object value類型錯誤:循環對象值

because of the constructs I mentioned.因爲我提到的構造。

How could I work around this?我該如何解決這個問題? It does not matter to me whether these references to other nodes are represented or not in the serialized object.這些對其他節點的引用是否在序列化對象中表示對我來說無關緊要。

On the other hand, removing these properties from the object when they are being created seems tedious and I wouldn't want to make changes to the parser (narcissus).另一方面,在創建對象時從對象中刪除這些屬性似乎很乏味,我不想對解析器(水仙)進行更改。


解決方案:

參考一: https://en.stackoom.com/question/dMjH
參考二: https://stackoom.com/question/dMjH
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章