Reputation: 15835
The following conversion fails saying bad control character
var myObj = JSON.parse('{"imagePath": "http://somedomain.com/test.jpg?path=\728\1.jpg"}');
console.log(myObj);
is that because of the following characters "\" in the image path , if so do we have any solution for this?
If i remove that character it works.
Thanks.
Upvotes: 0
Views: 124
Reputation: 7466
\
is an escape character. So if you want to use \
in your image Path string, then you need to double escape it. i.e. use \\
Upvotes: 1
Reputation: 39192
You need to escape the \
character whereever you are generating the JSON.
If it is a literal, then you have to escape the escapes also:
j = JSON.parse('{"imagePath": "http://somedomain.com/test.jpg?path=\\\\728\\\\1.jpg"}');
Upvotes: 1