Java Utililty Methods Json Encode

List of utility methods to do Json Encode

  1. HOME
  2. Java
  3. J
  4. Json Encode

Description

The list of methods to do Json Encode are organized into topic(s).

Method

String jsonEncode(final String val)
Encode a json string according to the statement:

In JSON only the backslash, double quote and ASCII control characters need to be escaped.

if ((val == null) || (val.length() == 0)) {
 return "\"\"";
StringBuilder sb = new StringBuilder();
sb.append('"');
for (int i = 0; i < val.length(); i++) {
 char ch = val.charAt(i);
 switch (ch) {
...
String jsonEncodeString(String text)
Lets make sure we encode the given string so its a valid JSON value which is wrapped in quotes if its not null
if (text == null) {
 return "null";
StringBuilder buffer = new StringBuilder("\"");
int length = text.length();
for (int i = 0; i < length; i++) {
 char ch = text.charAt(i);
 if (ch == '"') {
...

AltStyle によって変換されたページ (->オリジナル) /