Define “cyclic data structures”

前端 未结 9 1833
鱼传尺愫
鱼传尺愫 2021-02-02 09:33

At the JSON site it says

JSON does not support cyclic data structures, so be careful to not give cyclical structures to the JSON stringifier.

<
9条回答
  •  悲&欢浪女
    2021-02-02 10:05

    If you imagine the members of the data structure laid out as a graph, a cyclic data structure is where a member refers back to another one or the structure itself.

    For example:

    var obj = new Object();
    
    obj.left = new Object();
    
    obj.left.left = obj;
    

    This is impossible to represent in JSON, you would need to refer to the outer {} part somehow:

    { "left": { "left": ??? } }
    

提交回复
热议问题