我有一个变量:
var value=[
{"0","0",650,"0","0",357,"0","0","0","0",200,"0",48,"0",3053,"0","0","0","0","0",45,50}
,{"0","0",299,101,"0",126,"0","0","0","0",630,"0","0",88,3157,"0","0","0","0","0",10,21}
,{"0","0",123,3030,"0",368,"0","0","0","0","0","0",76,-44,1967,"0","0","0","0","0",29,64}
,{"0","0",88,343,"0",320,"0","0","0","0","0","0",175,"0",336,"0","0","0","0","0",21,98}
,{"0","0",503,410,"0",1127,"0","0","0","0","0","0",77,87,1264,"0","0","0","0","0",5,128}
,{"0","0",1754,607,40,2565,"0","0","0","0","0","0",102,70,12506,"0","0","0","0","0",178,1966}
,{"0","0","0","0",60,153,"0","0","0","0","0","0","0","0","0","0","0","0","0","0",15,"0"}
]
var result= JSON.parse(value);
当我在javacript中将其解析为JSON时,会发生错误:
未捕获的SyntaxError:意外的令牌,
答案 0 :(得分:1)
JSON中的对象用{}
表示。对象具有键值对。例如:
{
"foo": "bar",
"example: "something",
"key": "value"
}
JSON中的数组用[]
表示。它们是数字,字符串,对象等的列表。例如:
[
"foo",
"bar",
"something",
"example"
]
您的问题是您使用{}
作为数组。尝试将您的JSON更改为:
[
["0","0",650,"0","0",357,"0","0","0","0",200,"0",48,"0",3053,"0","0","0","0","0",45,50,["0","0",299,101,"0",126,"0","0","0","0",630,"0","0",88,3157,"0","0","0","0","0",10,21],["0","0",123,3030,"0",368,"0","0","0","0","0","0",76,-44,1967,"0","0","0","0","0",29,64],["0","0",88,343,"0",320,"0","0","0","0","0","0",175,"0",336,"0","0","0","0","0",21,98],["0","0",503,410,"0",1127,"0","0","0","0","0","0",77,87,1264,"0","0","0","0","0",5,128],["0","0",1754,607,40,2565,"0","0","0","0","0","0",102,70,12506,"0","0","0","0","0",178,1966],["0","0","0","0",60,153,"0","0","0","0","0","0","0","0","0","0","0","0","0","0",15,"0"]
]
此外,在JavaScript中,JSON是默认的Object Notation,因此除非您的JSON被表示为字符串,否则您不需要调用JSON.parse
。
答案 1 :(得分:0)
Javascript中的对象无法以这种方式呈现:
{"0","0",650,"0","0",357,"0","0","0","0",200,"0",48,"0",3053,"0","0","0","0","0",45,50}
对象呈现应具有以下格式:
{property_name : property_value, ... : ... , ... }
JSON.parse
期待':'
,但获得了','
。