Reputation: 5829
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:
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);
});
Upvotes: 2
Views: 18387
Reputation: 4739
The problem is the \r and \n. These need to be escaped as
\\r
and
\\n
in the JSON string
Upvotes: 2
Reputation: 4689
You need to escape your escapes :)
Use double \\
instead of \
Upvotes: 9