When parsing a JSON object I am getting "bad control character" error in the Firebug console. There are lot of questions and solutions in this site; but I am unable to crack this issue. I believe I am doing something silly. Please point me to my mistake.
JS Fiddle: http://jsfiddle.net/Purus/Eqz2r/
If we change the json data to a plain text instead of html tags, it works.
Error:
SyntaxError: JSON.parse: bad control character in string literal
someVal = JSON.parse(sign);
NOTE:
- The JSON data is obtained from a PHP function using json_encode function.
- The json output looks valid in jsonlint
Below is the code I have used.
$(document).ready(function () {
var sign = '{"data":"<br\/><br\/>----------<br \/>\r\nFrom Yahoo Team<br \/>\r\n<a href=\"http:\/\/localhost\/base\/1-yahoo-logo.jpg\" target=\"_blank\"><img style=\"padding: 5px;\" src=\"http:\/\/localhost\/plugins\/1-yahoo-logo.jpg\" height=\"120\" width=\"196\" \/><\/a>"}';
someVal = JSON.parse(sign);
$(".demo").append(someVal.data);
});