简体   繁体   中英

How to replace incorrectly unescaped double quotes in json string

I have json string which has double quotes in one of the value are not escaped.

Can any one please help me to identify it and escape. here is the example.

String s="{\"name\":\"son"o"o\",\"salary\":600000.0,\"age\":27}";  

I want to escape the double quotes surrounded by "o".

In JSON, double quotes need to be escaped with a backspace ( \" ), so the correct sequence is:

String s = "{\"name\":\"son\\\"o\\\"o\",\"salary\":600000.0,\"age\":27}";

Here we have:

  • \\ to insert a backspace
  • \" to insert a double quote

This results in the following JSON output:

{"name":"son\"o\"o","salary":600000.0,"age":27}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM