Here you can find the source of sanitizeForJson(String data)
public static String sanitizeForJson(String data)
//package com.java2s; public class Main { /**/*from www .ja va 2 s . c om*/ * Sanitize a string for inclusion in a JSON string Because most browsers * will interpret HTML tags e.g. </script> that appear in Javascript as * document level elements. Works by replacing angle brackets with their * character literal equivalents. See * http://www.wwco.com/~wls/blog/2007/04/25 * /using-script-in-a-javascript-literal/ for discussion of the problem and * the solution. */ public static String sanitizeForJson(String data) { data = data.replace("<", "\\x3C"); data = data.replace(">", "\\x3E"); // UI-destroying LINE-SEPERATOR character of doom. It's really rare, so lets just replace it. data = data.replace("\u2028", ""); return data; } }