Java Json Escape JsonEscape(String str)

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

Description

Json Escape

License

Open Source License

Declaration

public static String JsonEscape(String str) 

Method Source Code

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

public class Main {
    public static String JsonEscape(String str) {
        return EscapeForHtml(str).replace("\\", "\\\\");
    }/*from w  w  w .  jav a  2s  . c o  m*/

    public static String EscapeForHtml(String str) {
        str = str.replaceAll("'", "'");
        str = str.replaceAll("\"", """);
        str = str.replaceAll("<", "&lt;");
        str = str.replaceAll(">", "&gt;");
        str = str.replaceAll("\\\\n", "<br>");
        return str;
    }
}

Related

  1. escapeJSON(String aText)
  2. jsonEscape(CharSequence s)
  3. jsonEscape(String in)
  4. jsonEscape(String s)
  5. jsonEscape(String str)
  6. jsonEscape(String string)
  7. jsonEscapes(String str)