2016-12-19 67 views
1

我有一個JSON數據,我需要在HTML頁面中顯示,它只是一個文本,但文本只有很少的HTML標記用於樣式化。我不確定是哪個導致錯誤解析它。JSON中的HTML標記不允許解析它

{ 
     "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>" 
} 

任何人都可以告訴解析錯誤的路由是什麼?

+0

正常工作對我來說:[的jsfiddle(https://jsfiddle.net/5r7urhvo/) – Rajesh

+0

你能否包括你得到的錯誤以及導致它的任何相關代碼? – mike510a

回答

1

你誤解的問題。它與標籤無關。

JSON字符串不能包含文字新行。你應該用\n替換它們。

0

如果以上data您發佈的問題是returned data你不需要解析它,因爲它已經是json 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; 

Here is jsfiddle

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>" 
} 

```