circumvent ERROR Converting circular structure to JSON when doing JSON.stringify()?

前端 未结 4 697
予麋鹿
予麋鹿 2020-12-06 02:03

For debugging I want to serialize javascript objects with JSON.stringify(myobject). But this gives:

TypeError: Converting circular structure to JSON
<         


        
4条回答
  •  执念已碎
    2020-12-06 02:20

    JSON.stringify(obj) does not support circular referencing such as:

    var car = {}
    car.myself = car;
    JSON.stringify(car);
    

    However dojox.json.ref does support circular referencing, if you wanted to explore another option.

    However if your purposes are strictly to debug, I'd suggest using the built in browser debugger such as Chrome's, IE's or Firebug(for firefox).

提交回复
热议问题