I have an entry coming from database in the below format. I first used replaceAll instead of replace function but SonarCloud show error and asks to change from replaceAll to replace. However, the replace dosen't replace all the backslash, infact it does not change anything in the text.
Entry from database in java code:
""{\"id\":\"5947223f-9c50-425f-950b-e126c94b3adf\",\"name\":\"shruti\"}
With replaceAll I wrote code as below which works fine:
abcString.replaceAll("\\\\", "").replaceFirst("\"","");
To make SonarCloud happy, I try to change replaceAll with replace which in turn tell be to remove replaceFirst method otherwise it removes the both the double quotes from the database output.
Code with replace function:
abcString.replace("\\\\", "")
The second thing that I tried gives error:
Unexpected character ('\' (code 92)): was expecting double-quote to start field name
! at [Source: (String)"{\"id\":\"5947223f-9c50-425f-950b-e126c94b3adf\",\"name\":\"shruti\"}