Reputation: 33
I have a stringified JSON-Object inside another JSON-Object. I get it via $.ajax()
from my database like this:
data => {"foo":"[{\"foo\":\"bar\"},{\"foo2\":\"bar2\"}]"}
When trying to do JSON.parse(data.foo)
, I get an Uncaught SyntaxError: Unexpected token \
.
What am I doing wrong? (Apart from the fact, that the object needs to be saved as a string.)
Upvotes: 0
Views: 109
Reputation: 33
Thank you for your help. It seems, the data coming from the database "looked" right, but wasn't. I assume this was because I put the data in the database by hand. Now I put the data via my API with JSON.stringify() and now everythings looks fine.
Upvotes: 0
Reputation: 400
You have to escape html tags. Which language are you using in back end? In python Django it is done by using the safe filter. Similar might exist in php or other languages.
Upvotes: 1