class Point{ x = 0; y = 0; z = 0; toJSON(){ return [this.x,this.y]; } } let point = new Point(); console.log(JSON.stringify(point));
JS | TS 自定义 object 的 json 序列化
原文:https://www.cnblogs.com/chilli-with-fish/p/15180716.html