0

私は基本的に、DrawSomething によく似た、ユーザーが他の何かの描画を見ることができるキャンバス アプリケーションを作成しています。

1つの文字列を機能させることができます例:

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 に答える