我有一个带有样式标记的JSON响应。当我用jsonlint验证时,它显示无效的JSon。请有人帮我解决这个问题。当我尝试执行代码时,firefox提供了正确的输出。但只有IE导致了这个问题。
例如:
{
"contentHTML": "<style type=\"text/css\">\nbody\n{\n margin:0;
\n \n}\n\n.centerComponents\n{\n margin:auto;
\n text-align:left;
\n}\n\n#element1\n{\n width:984px;
\n}\n\n#c1315402137156\n{\n width:984px;
\n min-height:98px;
\n height:auto !important;
\n height:98px;
\n display:inline;
\n float:left;
\n}\n\n#c1315402137155\n{\n width:984px;
\n min-height:150px;
\n height:auto !important;
\n height:150px;
\n margin:2px 0 0 0;
\n display:inline;
\n float:left;
\n}\n\n#element2\n{\n width:984px;
\n display:inline;
\n float:left;
\n}\n\n#element3\n{\n width:243px;
\n display:inline;
\n float:left;
\n}\n\n#c1315402137154\n{\n width:243px;
\n min-height:547px;
\n height:auto !important;
\n height:547px;
\n margin:20px 0 0 0;
\n display:inline;
\n float:left;
\n}\n\n#c1315402137157\n{\n width:100px;
\n min-height:100px;
\n height:auto !important;
\n height:100px;
\n margin:27px 138px 0 5px;
\n display:inline;
\n float:left;
\n}\n\n#element4\n{\n width:740px;
\n margin:0 0 0 1px;
\n display:inline;
\n float:left;
\n}\n\n#c1315402137257\n{\n width:740px;
\n min-height:5px;
\n height:auto !important;
\n height:5px;
\n margin:30px 0 0 0;
\n display:inline;
\n float:left;
\n}\n\n#c1315402137158\n{\n width:740px;
\n min-height:423px;
\n height:auto !important;
\n height:423px;
\n margin:1px 0 0 0;
\n display:inline;
\n float:left;
\n}\n\n#c1315402137159\n{\n width:740px;
\n min-height:994px;
\n height:auto !important;
\n height:994px;
\n display:inline;
\n float:left;
\n}\n\n<\/style>"
}
答案 0 :(得分:1)
我认为这是因为你的JSON中有新行(实际换行符,而不是\n
序列),这是JavaScript,这是不允许的。
无效:
var a = "Hello
World";
有效:
var a = "Hello World";