我基本上是在创建一个画布应用程序,用户可以在其中看到其他内容的绘图,就像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"}]');
任何帮助将不胜感激!
答案 0 :(得分:0)
您的JSON无效。它包含一个数组数组。你需要用方括号包围外部数组,如下所示:
var points = JSON.parse(' [ [{“x”:10,“y”:20,“strokeStyle”:“FF0000”},{“x”:20,“ Y “:30” 的StrokeStyle “:” FF0000 “}],[{” × “:30,” Y “:40”,的StrokeStyle “:” 00FF00 “},{” × “:10,” Y“:20 “的StrokeStyle”: “FF0000”}],[{ “×”:50, “Y”:100, “的StrokeStyle”: “0000FF”},{ “×”:70, “Y”:120, “的StrokeStyle” : “0000FF”}]的 强>');