我尝试解析经过JSON验证的字符串时收到此错误("JSON.parse:意外字符").当我删除需要转义的字符时,它完美地工作(style ="width:400px;").我错过了什么?在使用parseJSON之前是否有一种独特的方法来转义字符?
var $cookieString = '{"youTabItems": { "youTab-001": <p style=\"width:400px;\">Welcome to my test</p>, "youTab-002": "test02Value", "youTab-003": "test03Value" }}';
var $myCookieString = $.parseJSON($cookieString);
logThis($myCookieString);
Run Code Online (Sandbox Code Playgroud)
更新
我能够让它的大部分工作,直到我开始从cookie保存/检索.现在,它在分号后切断了内容......对此有何想法?我在quirsmode.com上使用了3个函数来获取cookie功能(如下所示).
function setCookie(name, value, days) { var date, expires; if (days) { date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); expires = "; expires=" + date.toGMTString(); } else { expires = ""; } document.cookie = name + "=" + value + expires + "; path=/"; }
function getCookie(name) { …Run Code Online (Sandbox Code Playgroud)