I'm using PHP to fetch JSON stored in a MySQL database, put it into a PHP variable, and pass it to JQuery, which writes the content to the page:
data = $.parseJSON('<?=$my_json;?>');
$.each(data.links, function(entryIndex, entry) {
//do some stuff here
});
Everything works fine when the JSON looks like this:
{
"links": [{
"url": "http://domain1.com",
"title": "Title 1",
"description": "This is an example for my question on Stack Overflow"
}, {
"url": "http://domain2.com",
"title": "Title 2",
"description": "This is another example for my question on Stack Overflow"
}, {
"url": "http://domain3.com",
"title": "Title 3",
"description": "This is a third example for my question on Stack Overflow"
}]
}
But when the JSON content includes quotes, I get an error reading "Uncaught SyntaxError: Unexpected end of JSON input," even though the quotes are escaped, like this:
{
"links": [{
"url": "http://domain1.com",
"title": "Title 1",
"description": "This is an \"example\" for my question on Stack Overflow"
}, {
"url": "http://domain2.com",
"title": "Title 2",
"description": "This is another \"example\" for my question on Stack Overflow"
}, {
"url": "http://domain3.com",
"title": "Title 3",
"description": "This is a third \"example\" for my question on Stack Overflow"
}]
}
What am I doing wrong?