From the backend I am getting JSON that contains "key": "\$hello"
and I always get Unexpected token d. Is there something in angular I can use to escape these after I get them back from the server?
Asked
Active
Viewed 269 times
0

pcproff
- 612
- 1
- 8
- 30
-
1Can you not escape them properly when generating the _JSON_? It looks like you're probably missing an escape step – Paul S. Nov 09 '15 at 17:17
-
I don't touch the back end which is the problem in this case. – pcproff Nov 09 '15 at 17:25
-
Do you happen to know what the server side language is? This may not be an escape error as much as it's a concatenation error. A string leading with `$hello` leads me to believe that this should be a value, perhaps based on a `$hello` variable in PHP. Before you try to correct the incorrect escape sequences you may want to verify that the server side data returned is actually what you're expecting. Note that for some server side languages, especially PHP, concatenating values within different types of quotes can change the expected output. – War10ck Nov 09 '15 at 18:24
-
For the last part of my previous comment, see http://stackoverflow.com/questions/3446216/what-is-the-difference-between-single-quoted-and-double-quoted-strings-in-php – War10ck Nov 09 '15 at 18:26
-
Hey War10ck thanks for the response. That is an string value that I need to pass in to use as a reference as a uniqueID for example. The issue that all JSON validators seem to have is the '\'. I need to keep the '\' because it is part of the ID and that ID has to be passed to the back end to set a value there. – pcproff Nov 09 '15 at 18:31
1 Answers
0
You could simply run your JSON through a function to strip away all the unwanted characters:
function escapeSpecialChars(jsonString) {
return jsonString.replace("\$", "");
}

sjokkogutten
- 2,005
- 2
- 21
- 24
-
This is a good solution but I need to escape it not remove altogether :/ – pcproff Nov 09 '15 at 18:31