我正在尝试将KineticJS对象(带有一个添加的属性)序列化为JSON,但是如果我调用JSON.stringify(test);
,它只返回KineticJS对象的JSON表示而没有添加属性。有人知道吗,请问哪里有问题?
test = new Kinetic.Line(
{
points : [ 29, 30, 31, 32 ],
stroke : 'black',
strokeWidth : 2,
lineJoin : 'round',
id : '#line'
});
test.obj = "my own property";
JSON.stringify(test);
返回
{"attrs":{"points":[{"x":29,"y":30},{"x":31,"y":32}],"stroke":"black","strokeWidth":2,"lineJoin":"round","id":"#line"},
"nodeType":"Shape","shapeType":"Line"}"
但我还需要有关test.obj的信息..
答案 0 :(得分:2)
你可以这样做:
var test = new Object();
test.kinetic = new Kinetic.Line(
{
points : [ 29, 30, 31, 32 ],
stroke : 'black',
strokeWidth : 2,
lineJoin : 'round',
id : '#line'
});
test.obj = "my own property";
console.log(JSON.stringify(test));