2013-07-05 45 views
0

我基本上创建了一个画布应用程序,用户可以在其中看到其他画的东西,很像DrawSomething。多个JSON对象到画布中

我可以得到一个字符串上班前:

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

您的JSON无效。它包含一个数组数组。需要围绕用方括号外阵列,这样的:

VAR点= JSON.parse(” [ [{ “×”:10, “Y”:20, “的StrokeStyle”: “FF0000” },{ “×”:20, “Y”:30 “的StrokeStyle”: “FF0000”}],[{ “×”:30, “Y”:40 “的StrokeStyle”: “00FF00”},{” X “:10,” Y “:20,” 的StrokeStyle “:” FF0000 “}],[{” × “:50,” Y “:100,” 的StrokeStyle “:” 0000FF “},{” ד:70 ,“y”:120,“strokeStyle”:“0000FF”}] ]');

+0

哦哇失败了,我什至没有看到,谢谢! – jamesbar