Remove all occurrences of \ from string

Actually the correct way would be:

String jsonFormattedString = jsonStr.replace("\\\"", "\"");

You want to replace only \" with ", not all \ with nothing (it would eat up your slashes in json strings, if you have ones). Contrary to popular believe replace(...) also replaces all occurrences of given string, just like replaceAll(...), it just doesn't use regexp so it usually be faster.


Try this:

String jsonFormattedString = jsonStr.replaceAll("\\\\", "");

Because the backslash is the escaping character in a regular expression (replaceAll() receives one as parameter), it has to be escaped, too.