Here you can find the source of toJson(String org)
public static String toJson(String org)
//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("""); else if (chars[i] == '\'') result.append("'"); else if (chars[i] == '\\') result.append("\"); 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(); } }