json字符串如下
String str = "{\\\"name\\\":\\\"spy\\\",\\\"id\\\\":\\\"123456\\\"}";
maven引用
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.1</version>
</dependency>
使用 StringEscapeUtils中的转义与反转义
String str = "{\\\"name\\\":\\\"spy\\\",\\\"id\\\\":\\\"123456\\\"}";
System.out.println("原始 str = " + str);
String str1 = StringEscapeUtils.unescapeJava(str);
System.out.println("目标 str1 = " + str1);
输出结果
原始 str = {\"name\":\"spy\",\"id\":\"123456\"}
目标 str1 = {"name":"spy","id":"123456"}
网友评论