[{'question':'<p><strong>考试考试&nbsp;&nbsp; </strong><span style="color:#FF0000;">fdsfa</span</p>','answer':'dsf'}]
里面的“style”后有“"”会破坏json格式,怎么办呢?

解决方案 »

  1.   

    转义啊style=\"color:#FF0000;\"
    你json里为什么还要放标签
    放数据么就行了
    标签去浏览器端用js生成
      

  2.   

    你写的这个没问题啊,也不需要转义,像下面这种情况就需要转义了:
    var ar = [{"DEMO": "123\"abc\""}];
      

  3.   

    会提示unterminated string literal

    ([{'question':'<p><strong>考试考试</strong><span style=\)
    的问题
      

  4.   

    ["]引号还真不能破坏json,你的问题应该不是出在["]号上。你可以通过下面测试一下
    var question = {'question':'<p><strong>考试考试&nbsp;&nbsp; </strong><span style="color:#FF0000;">fdsfa</span</p>','answer':'dsf'};
    alert(question.question);
      

  5.   

    单双引号 嵌套着用的话,不用转义
    比如这样
    var json = {
    "style": "<div style='color:red'>123</div>"
    }
    如果这样的话就需要转义
    var json = {
    "style": "<div style=\"color:red\">123</div>"
    }
      

  6.   


    在js里面这样写 document.createElement('p')这样哇,我觉得返回的数据不应该参杂着html样式代码的