mirror of
https://github.com/fangyidong/json-simple.git
synced 2025-12-06 15:30:54 +03:00
15 lines
387 B
Markdown
15 lines
387 B
Markdown
#### Escaping text that contains special characters ####
|
|
JSONObject.escape() escapes quotes,\, /, \r, \n, \b, \f, \t and other control characters. It can be used to escape JavaScript codes.
|
|
|
|
```
|
|
String s = "\"foo\" is not \"bar\". specials: \b\r\n\f\t\\/";
|
|
|
|
s = JSONObject.escape(s);
|
|
|
|
System.out.println(s);
|
|
```
|
|
|
|
Result:
|
|
```
|
|
\"foo\" is not \"bar\". specials: \b\r\n\f\t\\\/
|
|
``` |