I'm creating json string to send to the server. I use GSon to generate json string. Because my server doesn't understand string like: \"key\":value
but "key":value
or "a\/b"
but a/b
. So after generating json string, I use replaceAll
method to fix this:
String res = original.replaceAll("\\/", "/").replaceAll("\\"", "\"");
But this method doesn't work as I expected. Please tell me how to replace string to conform with server as above.
Thanks :)
\"
\\"
\\\\"
\\\\\"
You want to replace by a double-quote, so the point #4 needs to be applied again:
.replaceAll("\\\\\"", "\"")
Same logic for the other replacement (without the point #4 since no double-quote):
.replaceAll("\\\\/", "/")
Combined into one single regex:
.replaceAll("\\\\([\"/])", "$1")