When trying to parse a JSON-string using the JQuery.parseJSON function, I encountered an error message that read:
Uncaught SyntaxError: Unexpected token R
. This was unusual as the only uppercase 'R' in my JSON-formatted string appeared right after an escaped quotation mark (... \"R ...
). It seemed like too much of a coincidence for it to be caused by anything else. I double-checked my syntax against json.org but couldn't find any errors.
UPDATE:
To troubleshoot, I manually removed all instances of \"
in a hardcoded test and successfully formatted the string into a valid Javascript object. So, it's clear that \"
is causing the issue...
var myObject = $.parseJSON(myString);
UPDATE 2:
I've displayed the problematic section of my string both with and without the issue. First, the problematic one:
{"lineID":33,"boxID":10,"title":"My text with the \"Ruining Part\""}
And now, the working version:
{"lineID":33,"boxID":10,"title":"My text with the Ruining Part"}
Lastly, here's how I format my JavaBean object into a JSON string.
String jsonObjectAsString = new Gson().toJson(myJavaBeanObject);