2016-02-28 97 views
-4

我有一個變量:JSON解析:未捕獲的SyntaxError:意外令牌,使用Javascript

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解析它,將發生錯誤:在JSON

Uncaught SyntaxError: Unexpected token ,

+1

你期望什麼? – Amit

+3

有許多json驗證器可以在來這裏之前粘貼到這裏。更何況,這裏甚至沒有問題 – charlietfl

+1

不更新問題的解決方案...它呈現原來的問題和答案沒用 – charlietfl

回答

1

對象被表示與{}。對象有鍵值對。例如:在JSON

{ 
    "foo": "bar", 
    "example: "something", 
    "key": "value" 
} 

數組表示與[]。他們是數字,字符串,對象等的列表例如:

[ 
    "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是默認的對象符號,所以你不需要調用JSON.parse除非你的JSON被表示爲一個字符串。在Javascript

0

對象不能以這樣的方式呈現:

{"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期待':',但得到','

相關問題