JSON解析字符串有Apostrophe(单引号)

时间:2015-10-08 10:01:33

标签: javascript

如何解析以下字符串

var a = JSON.parse('[' + '{"NoteName":"it's my life","UserId":"100","NoteActive":true,"UserEmail":"admin@dev.xrc.com","CreatedDate":"8/13/2012 1:47:35 PM"}' + ']');

3 个答案:

答案 0 :(得分:7)

你只需要逃避单引号it\'s

var a = JSON.parse('[' + '{"NoteName":"it\'s my life","UserId":"100","NoteActive":true,"UserEmail":"admin@dev.xrc.com","CreatedDate":"8/13/2012 1:47:35 PM"}' + ']');
console.log(a);

答案 1 :(得分:2)

您可以使用反斜杠转义(仅作为字符解释)引号。 “\”“或'\''

答案 2 :(得分:2)

it's替换为it\'s

'[' + '{"NoteName":"it\'s my life","UserId":"100","NoteActive":true,"UserEmail":"admin@dev.xrc.com","CreatedDate":"8/13/2012 1:47:35 PM"}' + ']'