我在解析javascript对象中的特殊字符时遇到问题。
转义的数字会导致问题和双引号字符对我造成问题:
JSON.parse('[{"title":"Turpial 3 Beta Builds Available for Ubuntu","description":"<p><img width=\"350"}]');
SyntaxError: Unexpected number
message: "Unexpected number"
stack: (...)
get stack: function () { [native code] }
set stack: function () { [native code] }
__proto__: Error
JSON.parse('[{"title":"Turpial 3 Beta Builds Available for Ubuntu","description":"<p><img width=\""}]');
SyntaxError: Unexpected string
message: "Unexpected string"
stack: (...)
get stack: function () { [native code] }
set stack: function () { [native code] }
__proto__: Error
JSON.parse('[{"title":"Turpial 3 Beta Builds Available for Ubuntu","description":"<p><img width="}]');
[
Object
]
答案 0 :(得分:1)
您的输入字符串未针对JavaScript正确转义。使用双反斜杠来转义双引号:
JSON.parse('[{"title":"Turpial 3 Beta Builds Available for Ubuntu","description":"<p><img width=\\"350"}]');