2013-07-05 80 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