忽略转义的工具类, org.apache.commons.lang.StringEscapeUtils,其中unescapeJava(String s)方法是来处理java转义字符的,可以将字符串中的 “\”转换为 “\”,“'”转换为“'”等。通过这个方法处理以上字符串
package day01;
import org.apache.commons.lang.StringEscapeUtils;
public class StringEscapeUtils_Test {
public static void main(String[] args) {
// String s = "\\u79fb\\u52a8\\u4e92\\u8054\\u7f51\\u5e94\\u7528";
String s = "{\n" + "\t\"id\":2, \"name\":\"大虾\", \n" + "\t\"price\":12.3, \n"
+ "\t\"imagePath\":\"http://192.168.10.165:8080/L05_Server/images/f1.jpg\"\n" + "}\n";
String s2 = StringEscapeUtils.unescapeJava(s);
System.out.println("s:"+s);
System.out.println("s2:"+s2);
}
}