Java Json Escape jsonEscape(CharSequence s)

Here you can find the source of jsonEscape(CharSequence s)

Description

Escapes json characters in the passed string

License

LGPL

Parameter

Parameter Description
s The string to esacape

Return

the escaped string

Declaration

public static String jsonEscape(CharSequence s) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

public class Main {
    /**//from w  w  w  .ja va 2s.  c o  m
     * Escapes json characters in the passed string
     * @param s The string to esacape
     * @return the escaped string
     */
    public static String jsonEscape(CharSequence s) {
        return s.toString().replace("\"", "\\\"").replace("[", "\\[").replace("]", "\\]").replace("{", "\\{")
                .replace("}", "\\}");
    }
}

Related

  1. escape4Json(String source)
  2. escapeJSON(String aText)
  3. jsonEscape(String in)
  4. jsonEscape(String s)
  5. JsonEscape(String str)
  6. jsonEscape(String str)