Java Json String Create toJson(String org)

Here you can find the source of toJson(String org)

Description

to Json

License

Open Source License

Declaration

public static String toJson(String org) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String toJson(String org) {
        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] == '\\')
                result.append("&#92");
            else if (chars[i] == '\r') {
                result.append("\\r");
            } else if (chars[i] == '\n')
                result.append("\\n");
            else/*w  w  w  . j  a  v  a 2  s .  c om*/
                result.append(chars[i]);
        }
        return result.toString();
    }
}

Related

  1. toJson()
  2. toJson(final Document doc)
  3. toJson(Object value)
  4. toJson(String jsonp)
  5. toJson(String s)
  6. toJson(String str)
  7. toJson(String str)
  8. toJSON(String string)