json -> 返回的响应
{"msg":"<DIV><P>Unfortunately we were unable to process your application.</p><BR>Please upload a CV<BR></DIV>", "status":"error"}
错误
SCRIPT1015:未终止的字符串常量
有错误的行
var data = $(this).contents().find('body').html();//I have console logged this and holds the above json as a string.
data = jQuery.parseJSON(data);// problem is here.
出于某种原因,我认为这可能是因为 html 标签,因为 .text()
的工作方式与 .html()
相反,但是我需要使用.html()
因为它是用 html 标签格式化的。
有什么建议吗?
最佳答案
这是 json 中的换行符吗?如果是这样的话,那就是你的错误。尝试使用 data.replace( '\n', ' ' )
之类的方法消除它。
评论更新:Val 意识到 IE8 解析器实际上在处理他的测试用例,而原始的 javascript JSON 解析器处理得很好。如果您需要原始解析器,它位于:https://github.com/douglascrockford/JSON-js链接至:http://www.json.org并且替换率几乎下降了。
关于jquery - IE8 上 json 解析失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9007740/