0

我基本上是在创建一个画布应用程序,用户可以在其中看到其他东西的绘图,很像 DrawSomething。

我可以让一个字符串工作,例如:

var points = JSON.parse ('[{"x":10,"y":20,"strokeStyle":"FF0000"},{"x":20,"y":30,"strokeStyle":"FF0000"}]');

但不是当我有倍数时:

var points = JSON.parse ('[{"x":10,"y":20,"strokeStyle":"FF0000"},
{"x":20,"y":30,"strokeStyle":"FF0000"}],[{"x":30,"y":40,"strokeStyle":"00FF00"},
{"x":10,"y":20,"strokeStyle":"FF0000"}],[{"x":50,"y":100,"strokeStyle":"0000FF"},
{"x":70,"y":120,"strokeStyle":"0000FF"}]');

任何帮助,将不胜感激!

4

1 回答 1

0

您的 JSON 无效。它包含一个数组数组。您需要用方括号将外部数组括起来,如下所示:

var points = JSON.parse (' [ [{"x":10,"y":20,"strokeStyle":"FF0000"},{"x":20,"y":30,"strokeStyle":" FF0000"}],[{"x":30,"y":40,"strokeStyle":"00FF00"},{"x":10,"y":20,"strokeStyle":"FF0000"}] ,[{"x":50,"y":100,"strokeStyle":"0000FF"},{"x":70,"y":120,"strokeStyle":"0000FF"}] ] ');

于 2013-07-05T15:11:44.787 回答