当有特殊字符时,JSON解析问题

时间:2013-12-24 08:51:30

标签: javascript

我有一个JSON结构,我想在JS中进行解析,但由于某些特殊字符,我得到无效的令牌错误,并且协议名称中的特殊字符使得JSON无效。有谁可以帮我解决这个问题?有没有办法解决这个问题?

的jsfiddle

  

http://jsfiddle.net/G5umj/

使用Javascript:

var new_var = '{"ERRMSG":"","REPORT_NAME":"MS_SRA_VISIT_LP","QUERY":{"COLUMNS":["col1"],"DATA":[{"V1-6441-2013-12":{"PROTOCOL_NAME":"Full Protocol AFTER FIXING ISSUE\\ K1\" K2\"\"\"\"  \"\'\' K3","AUDIT_COMPANY":[{"Golder":{"auditors":[{"NAME":"Sabrina moore"}]}}]}}],"summary":[]}}';

var new_J = JSON.parse(new_var);

1 个答案:

答案 0 :(得分:0)

应该是(jsfiddle):

var new_var = '{"ERRMSG":"","REPORT_NAME":"MS_SRA_VISIT_LP","QUERY":{"COLUMNS":["col1"],"DATA":[{"V1-6441-2013-12":{"PROTOCOL_NAME":"Full Protocol AFTER FIXING ISSUE\\\\ K1\\" K2\\"\\"\\"\\"  \\"\'\' K3","AUDIT_COMPANY":[{"Golder":{"auditors":[{"NAME":"Sabrina moore"}]}}]}}],"summary":[]}}';

var new_J = JSON.parse(new_var);

'" \" "' - 这是单引号中"的转义,但'" \\" "'无法用双引号转义:)