List of utility methods to do Json Encode
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 == '"') { ... |