Nikhil Bharadwaj
Nikhil Bharadwaj

Reputation: 917

HTML tags in JSON not allowing to parse it

I have a JSON data which i need to show in a HTML page, its just a text, but the text has few HTML tags for styling puspose. I'm not sure which is causing the error to parse it.

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

Can anyone tell what is the route for parse error?

Upvotes: 1

Views: 690

Answers (3)

la3roug
la3roug

Reputation: 311

Try to put the text in a signle line like this:

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

```

Upvotes: 0

Quentin
Quentin

Reputation: 943562

You've misinterpreted the problem. It has nothing to do with the tags.

JSON strings may not contain literal new lines. You should replace them with \n.

Upvotes: 1

Mairaj Ahmad
Mairaj Ahmad

Reputation: 14604

If above data which you have posted in question is the returned data you dont need to parse it because it is already a 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

Upvotes: 0

Related Questions