Java Json Escape jsonEscapes(String str)

Here you can find the source of jsonEscapes(String str)

Description

json Escapes

License

Open Source License

Declaration

private static String jsonEscapes(String str) 

Method Source Code

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

public class Main {
    private static String jsonEscapes(String str) {
        //        System.out.println("ESCAPING "+str);
        StringBuilder escaped = new StringBuilder();
        for (int i = 0; i < str.length(); i++) {
            switch (str.charAt(i)) {
            case 0:
                continue;
            case '\b':
                escaped.append("\\\\b");
                continue;
            case '\t':
                escaped.append("\\\\t");
                continue;
            case '\n':
                escaped.append("\\\\n");
                continue;
            case '\f':
                escaped.append("\\\\f");
                continue;
            case '\r':
                escaped.append("\\\\r");
                continue;
            case '\"':
                escaped.append("\\\\\"");
                continue;
            case '\\':
                escaped.append("\\\\\\");
                continue;
            default:
                escaped.append(str.charAt(i));
                continue;
            }//from ww w . ja  v  a  2 s . co m
        }
        return escaped.toString();
    }
}

Related

  1. jsonEscape(String in)
  2. jsonEscape(String s)
  3. JsonEscape(String str)
  4. jsonEscape(String str)
  5. jsonEscape(String string)