反序列化JSON字符串,KineticJS,我们可以使用动态节点创建()方法创建一个节点从一个JSON字符串。如果我们想要序列化一个阶段节点,我们也可以通过一个可选的容器参数。
<!DOCTYPE HTML>
<html>
<head>
<style>
body {
margin: 0px;
padding: 0px;
}
</style>
</head>
<body>
<div id="container"></div>
<script src="http://d3lp1msu2r81bx.cloudfront.net/kjs/js/lib/kinetic-v4.7.0.min.js"></script>
<script defer="defer">
var json = '{"attrs":{"width":578,"height":200},"className":"Stage","children":[{"attrs":{},"className":"Layer","children":[{"attrs":{"x":289,"y":100,"sides":6,"radius":70,"fill":"red","stroke":"black","strokeWidth":4},"className":"RegularPolygon"}]}]}';
// create node using json string
var stage = Kinetic.Node.create(json, 'container');
</script>
</body>
</html>