本地存储编辑不起作用

时间:2014-03-27 19:49:27

标签: javascript google-chrome local-storage

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}');

我的脚本只是一个简单的脚本,可以在chrome的浏览器栏中实现,但它会返回SyntaxError: Unexpected token ILLEGAL。我已经尝试将本地存储设置为简单的工具。有人可以告诉我出了什么问题或者重写它是否有效。

1 个答案:

答案 0 :(得分:0)

如评论中提到的那样,你有错误的缩进以及一些额外的空格和缺少的逗号。

  

localStorage.setItem( '游戏状态',   '{“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} {“值“: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}}]]},“得分”:272,“over”:false,“won”:false,“keepPlaying”:false} “);