문제

localStorage.setItem('gameState', '{"
grid ":{"
size ":4,"
cells ":[[{"
position ":{"
x ":0,"
y ":0},"
value ":1024},{"
position ":{"
x ":0,"
y ":1},"
value ":1024},{"
position ":{"
x ":0,"
y ":2},"
value ":1024},{"
position ":{"
x ":0,"
y ":3},"
value ":1024}],[{"
position ":{"
x ":1,"
y ":0},"
value ":1024},{"
position ":{"
x ":1,"
y ":1},"
value ":1024},{"
position ":{"
x ":1,"
y ":2},"
value ":1024},{"
position ":{"
x ":1,"
y ":3},"
value ":1024}],[{"
position ":{"
x ":2,"
y ":0},"
value ":1024},{"
position ":{"
x ":2,"
y ":1},"
value ":1024},{"
position ":{"
x ":2,"
y ":2},"
value ":1024},{"
position ":{"
x ":2,"
y ":3},"
value ":1024}],[{"
position ":{"
x ":3,"
y ":0},"
value ":1024},{"
position ":{"
x ":3,"
y ":1},"
value ":1024},{"
position ":{"
x ":3,"
y ":2},"
value ":1024},{"
position ":{"
x ":3,"
y ":3},"
value ":1024}]]},"
score ":272,"
over ":false,"
won ":false,"
keepPlaying ":false}');

My script is just a simple one meant to implement into the browser bar of chrome but it returns SyntaxError: Unexpected token ILLEGAL. I have tried setting the local storage to something simple and it works. Can someone tell me what is wrong or rewrite it so it works.

도움이 되었습니까?

해결책

Like mentioned in the comments, you had wrong indentation as well as some extra spaces and missing commas.

localStorage.setItem('gameState', '{"grid":{"size":4,"cells":[[{"position":{"x":0,"y":0},"value": 1024},{"position":{"x":0, "y": 1}{"value":1024}},{"position":{"x":0, "y": 1}{"value":1024}},{"position":{"x":0, "y": 1}{"value":1024}},{"position":{"x":0, "y": 1}{"value":1024}},{"position":{"x":0, "y": 1}{"value":1024}},{"position":{"x":0, "y": 1}{"value":1024}},{"position":{"x":0, "y": 1}{"value":1024}},{"position":{"x":0, "y": 1}{"value":1024}},{"position":{"x":0, "y": 1}{"value":1024}},{"position":{"x":0, "y": 1}{"value":1024}},{"position":{"x":0, "y": 1}{"value":1024}},{"position":{"x":0, "y": 1}{"value":1024}},{"position":{"x":0, "y": 1}{"value":1024}},{"position":{"x":0, "y": 1}{"value":1024}}]]},"score":272,"over":false,"won":false,"keepPlaying ":false}');

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top