class JsonUtils {

    public static String getJsonString(String string) {
        if (string == null || string.length() == 0) {
            return "\"\"";
        }
        StringBuilder jsonString = new StringBuilder();
        jsonString.append("\"");
        char[] charArray = string.toCharArray();
        for (char c : charArray) {
            switch (c) {
                case '\n':
                    jsonString.append("\\n");
                    break;
                case '\r':
                    jsonString.append("\\r");
                    break;
                case '\t':
                    jsonString.append("\\t");
                    break;
                case '\b':
                    jsonString.append("\\b");
                    break;
                case '\f':
                    jsonString.append("\\f");
                    break;
                case '\\':
                    jsonString.append("\\\\");
                    break;
                case '"':
                    jsonString.append("\\\"");
                    break;
                default:
                    if (c < '\u0010') {
                        jsonString.append("\\u000").append(Integer.toHexString(c));
                    } else if ((c < '\u0020' && c > '\u0009') || (c >= '\u0080' && c < '\u00a0')) {
                        jsonString.append("\\u00").append(Integer.toHexString(c));
                    } else if (c >= '\u2000' && c < '\u2100') {
                        jsonString.append("\\u").append(Integer.toHexString(c));
                    } else {
                        jsonString.append(c);
                    }
                    break;
            }
        }
        jsonString.append("\"");
        return jsonString.toString();
    }

    private  JsonUtils();

}