Java Utililty Methods Json String Create

List of utility methods to do Json String Create

Description

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

Method

StringtoJson()
Problem of Json is that we need to distinguish
throw new UnsupportedOperationException("Not supported yet.");
StringtoJson(final Document doc)
to Json
return toJson(doc, false);
StringtoJson(Object value)
to Json
return value.toString();
StringtoJson(String jsonp)
to Json
final String prefix = "loaded(";
final String suffix = ")";
return jsonp.substring(0 + prefix.length(), jsonp.length() - suffix.length());
StringtoJson(String org)
to Json
StringBuffer result = new StringBuffer(org.length());
char[] chars = org.toCharArray();
for (int i = 0; i < chars.length; i++) {
    if (chars[i] == '\"')
        result.append("&#34");
    else if (chars[i] == '\'')
        result.append("&#39");
    else if (chars[i] == '\\')
...
StringtoJson(String s)
Converts a String to a JSON String.
if (s != null) {
    StringBuilder sb = new StringBuilder();
    sb.append('"');
    int len = s.length();
    for (int i = 0; i < len; i++) {
        char c = s.charAt(i);
        switch (c) {
        case '\\':
...
StringtoJson(String str)
to Json
if (str == null) {
    return str;
StringBuilder sb = new StringBuilder();
int len = str.length();
for (int i = 0; i < len; i++) {
    char c = str.charAt(i);
    switch (c) {
...
StringtoJson(String str)
to Json
int len = str.length();
StringBuilder buf = new StringBuilder();
buf.append('\"');
for (int i = 0; i < len; i++) {
    char ch = str.charAt(i);
    if (ch == '\n')
        buf.append("\\n");
    else if (ch == '\r')
...
StringtoJSON(String string)
to JSON
if (string != null) {
    string = string.replace("\"", "\\\"");
return string;
String[]toJsonArrays(String... strings)
to Json Arrays
String[] jsonArrays = new String[strings.length];
for (int i = 0; i < strings.length; i++) {
    jsonArrays[i] = "[\"" + strings[i] + "\"]";
return jsonArrays;