0

I have a json string:

var jsonString = "{\"editor1\":\"<b>abc</b>\",\"editor2\":\"<ul><li style=\"text-align: center;\"><b><i><u><strike>abc</strike></u></i></b><br></li></ul>\",\"timepicker1\":\"00:11:01\"}"

I need to convert this to a json object. This string contains both html and non html data. I'm using json parser in my js as below:

var jsonObject = JSON.parse(jsonString);

but when its parsing the HTML Style bit I'm getting this error:

Syntax Error: Unexpected token t.

How can I parse an HTML Element using json parser? Should I use another parser?

1 Answer 1

1

If it were just an object, the code would look like

{
    "editor1":"<b>abc</b>",
    "editor2":"<ul><li style="text-align: center;"><b><i><u><strike>abc</strike></u></i></b><br></li></ul>",
    "timepicker1":"00:11:01"
}

Notice the "..."..."..."

You need to escape the " characters inside one more time

...\"editor2\":\"<ul><li style=\\"text-align: center;\\"><b><i>...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.