JSON中的HTML标记不允许解析它

时间:2016-12-19 10:18:37

标签: javascript html json

我有一个JSON数据,我需要在HTML页面中显示,它只是一个文本,但文本有很少的HTML标记用于样式puspose。我不确定哪个导致错误解析它。

{
        "NAME":"NEW",
        "ID":"01",
        "DETAILS":"HELLO NEW TEXT FOR TESTING(HERE COMES ONE <strong>TWO</strong>), arôme, <strong>FINE</strong> écrémé. FRESH: 47% minimum
<br>
<strong>LINE BREAK AND STRONG TEXT.</strong>"
}

任何人都可以告诉解析错误的路由是什么?

3 个答案:

答案 0 :(得分:1)

你误解了这个问题。它与标签无关。

JSON字符串可能不包含文字新行。您应该使用\n替换它们。

答案 1 :(得分:0)

如果你发布的data以上returned datajson object你不需要解析它,因为它已经是<div id="Name"></div> <div id="ID"></div> <div id="DETAILS"></div> var data = { "NAME": "NEW", "ID": "01", "DETAILS": "HELLO NEW TEXT FOR TESTING(HERE COMES ONE <strong>TWO</strong>), arôme, <strong>FINE</strong> écrémé. FRESH: 47% minimum < br >< strong > LINE BREAK AND STRONG TEXT. < /strong>" } document.getElementById("Name").innerHTML = data.NAME; document.getElementById("ID").innerHTML = data.ID; document.getElementById("DETAILS").innerHTML = data.DETAILS;

.postwrapper

Here is jsfiddle

答案 2 :(得分:0)

尝试将文字放在这样的符号行中:

{
    "NAME": "NEW",
    "ID": "01",
    "DETAILS": "HELLO NEW TEXT FOR TESTING(HERE COMES ONE <strong>TWO</strong>), arôme, <strong>FINE</strong> écrémé. FRESH: 47% minimum <br> <strong>LINE BREAK AND STRONG TEXT.</strong>"
}

```