简体   繁体   English

本地存储编辑不起作用

[英]Local Storage edit not working

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 . 我的脚本只是一个简单的示例,旨在实现在chrome浏览器栏中,但返回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}'); 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} {”值“:1024}},{”位置“:{” x“:0,” y“:1} {”值“:1024}},{”位置“ :{“ 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}}]]}},“得分”:272,“ over”:false,“ won”: false,“ keepPlaying”:false}');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM