我如何解析以下字符串JSON解析字符串
var a = JSON.parse('[' + '{"NoteName":"it's my life","UserId":"100","NoteActive":true,"UserEmail":"[email protected]","CreatedDate":"8/13/2012 1:47:35 PM"}' + ']');
我如何解析以下字符串JSON解析字符串
var a = JSON.parse('[' + '{"NoteName":"it's my life","UserId":"100","NoteActive":true,"UserEmail":"[email protected]","CreatedDate":"8/13/2012 1:47:35 PM"}' + ']');
你刚才逃脱单引号it\'s
var a = JSON.parse('[' + '{"NoteName":"it\'s my life","UserId":"100","NoteActive":true,"UserEmail":"[email protected]","CreatedDate":"8/13/2012 1:47:35 PM"}' + ']');
console.log(a);
可以逃脱(仅解释为字符)使用反斜杠的引号。 “\””或‘\’”
更换it's
与it\'s
'[' + '{"NoteName":"it\'s my life","UserId":"100","NoteActive":true,"UserEmail":"[email protected]","CreatedDate":"8/13/2012 1:47:35 PM"}' + ']'
你为什么要手工创建JSON,而不是使用'JSON.stringify'吗?那你就不必担心细节像这样,它会自动为你处理 – Barmar
这与解析JSON没有任何关系,你的问题基本上是关于如何在字符串周围使用撇号作为分隔符时将撇号放入字符串。 – Barmar