0
我試圖用JSON.parse('{..}')解析JSON代碼;在JavaScript 顯示錯誤「意外令牌非法」JSON解析我的JSON對象時出錯
var obj= JSON.parse('{
\t "single": [
\t {"id": "1","question": "this is a question1?","option": ["option1","option2","option3","option4"]},
\t {"id": "2","question": "this is a question2?","option": ["option1","option2","option3","option4"]},
\t {"id": "3","question": "this is a question3?","option": ["option1","option2","option3","option4"]},
\t {"id": "4","question": "this is a question4?","option": ["optionu1","optionu2","optionu3","optionu4"]}
\t ],
\t "multiple": [
\t {"id": "1","question": "this is a multiple question1?","option": ["optionm1","option2lj","option3","option4"]},
\t {"id": "2","question": "this is a multiple question2?","option": ["optionm1","option2j","option3","option4"]},
\t {"id": "3","question": "this is a multiple question3?","option": ["optionm1","option2gg","option3","option4"]},
\t {"id": "4","question": "this is a multiple question4?","option": ["optionm1","option2h","option3","option4"]}
\t ],
\t "integer": [
\t {"id": "1","question": "this is a int question1?"},
\t {"id": "2","question": "this is a int question2?"},
\t {"id": "3","question": "this is a int question3?"},
\t {"id": "4","question": "this is a int question4?"}
\t ]}');
我認爲錯誤是在支架matching.Please幫我糾正it.Thanks提前。
你可以使用反引號代替'''字符嗎? – Hackerman
其他然後在字符串中間的換行符,對我來說似乎很好 – adeneo
我猜測證明是在布丁 - > https://jsfiddle.net/9nrx7nsk/ – adeneo