java json转义与反转义

public class Test {
    public static void main(String[] args) {
        List<TestVO> testVOList = new ArrayList<>();
        TestVO testVO = new TestVO();
        testVO.setLocator("1");
        testVO.setLot("2");
        testVO.setMaterialLot("3");
        testVOList.add(testVO);
        System.out.println("未转义:" + JSONUtil.toJsonStr(testVOList));
        String escapeJson=StringEscapeUtils.escapeJson(JSONUtil.toJsonStr(testVOList));
        System.out.println("转义后:" + StringEscapeUtils.escapeJson(escapeJson));
        String unEscapeJson=StringEscapeUtils.unescapeJson(escapeJson);
        System.out.println("反转义后:" + unEscapeJson);
    }
}
D:\MyDemoSoft\Java\jdk1.8.0_101\bin\java.exe -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:51465,suspend=y,server=n -javaagent:C:\Users\14372\AppData\Local\JetBrains\IntelliJIdea2022.1\groovyHotSwap\gragent.jar -javaagent:C:\Users\14372\AppData\Local\JetBrains\IntelliJIdea2022.1\captureAgent\debugger-agent.jar -Dfile.encoding=GBK -classpath "D:\MyDemoSoft\Java\jdk1.8.0_101\jre\lib\charsets.jar;D:\MyDemoSoft\Java\jdk1.8.0_101\jre\lib\deploy.jar;D:\MyDemoSoft\Java\jdk1.8.0_101\jre\lib\ext\access-bridge-64.jar;D:\MyDemoSoft\Java\jdk1.8.0_101\jre\lib\ext\cldrdata.jar;D:\MyDemoSoft\Java\jdk1.8.0_101\jre\lib\ext\dnsns.jar;D:\MyDemoSoft\Java\jdk1.8.0_101\jre\lib\ext\jaccess.jar;D:\MyDemoSoft\Java\jdk1.8.0_101\jre\lib\ext\jfxrt.jar;D:\MyDemoSoft\Java\jdk1.8.0_101\jre\lib\ext\localedata.jar;D:\MyDemoSoft\Java\jdk1.8.0_101\jre\lib\ext\nashorn.jar;D:\MyDemoSoft\Java\jdk1.8.0_101\jre\lib\ext\sunec.jar;D:\MyDemoSoft\Java\jdk1.8.0_101\jre\lib\ext\sunjce_provider.jar;D:\MyDemoSoft\Java\jdk1.8.0_101\jre\lib\ext\sunmscapi.jar;D:\MyDemoSoft\Java\jdk1.8.0_101\jre\lib\ext\sunpkcs11.jar;D:\MyDemoSoft\Java\jdk1.8.0_101\jre\lib\ext\zipfs.jar;D:\MyDemoSoft\Java\jdk1.8.0_101\jre\lib\javaws.jar;D:\MyDemoSoft\Java\jdk1.8.0_101\jre\lib\jce.jar;D:\MyDemoSoft\Java\jdk1.8.0_101\jre\lib\jfr.jar;D:\MyDemoSoft\Java\jdk1.8.0_101\jre\lib\jfxswt.jar;D:\MyDemoSoft\Java\jdk1.8.0_101\jre\lib\jsse.jar;D:\MyDemoSoft\Java\jdk1.8.0_101\jre\lib\management-agent.jar;D:\MyDemoSoft\Java\jdk1.8.0_101\jre\lib\plugin.jar;D:\MyDemoSoft\Java\jdk1.8.0_101\jre\lib\resources.jar;D:\MyDemoSoft\Java\jdk1.8.0_101\jre\lib\rt.jar;D:\HandDemo\xm-mes-uat-0310\calb-mes\CALBMtFrame\core\target\classes;D:\MyDemoSoft\Maven\repos\net\sourceforge\jchardet\jchardet\1.0\jchardet-1.0.jar;D:\HandDemo\xm-mes-uat-0310\calb-mes\CALBMtFrame\core-db\target\classes;D:\MyDemoSoft\Maven\repos\com\hand\hap-core-db\3.5.4.1-RELEASE\hap-core-db-3.5.4.1-RELEASE.jar;D:\MyDemoSoft\Maven\repos\org\liquibase\liquibase-groovy-dsl\1.2.1\liquibase-groovy-dsl-1.2.1.jar;D:\MyDemoSoft\Maven\repos\org\codehaus\groovy\groovy-sql\2.4.1\groovy-sql-2.4.1.jar;D:\MyDemoSoft\Maven\repos\org\liquibase\liquibase-core\3.4.2\liquibase-core-3.4.2.jar;D:\MyDemoSoft\Maven\repos\org\codehaus\groovy\groovy\2.4.1\groovy-2.4.1.jar;D:\MyDemoSoft\Maven\repos\org\codehaus\groovy\groovy-all\2.4.1\groovy-all-2.4.1.jar;D:\MyDemoSoft\Maven\repos\org\codehaus\groovy\groovy-xml\2.4.1\groovy-xml-2.4.1.jar;D:\MyDemoSoft\Maven\repos\com\hand\hap-core\3.5.4.1-RELEASE\hap-core-3.5.4.1-RELEASE.war;D:\MyDemoSoft\Maven\repos\mysql\mysql-connector-java\5.1.34\mysql-connector-java-5.1.34.jar;D:\MyDemoSoft\Maven\repos\com\microsoft\sqlserver\sqljdbc4\4.2\sqljdbc4-4.2.jar;D:\MyDemoSoft\Maven\repos\com\oracle\ojdbc7\12.1.0.1.0\ojdbc7-12.1.0.1.0.jar;D:\MyDemoSoft\Maven\repos\com\sap\hana-jdbc\2.0.9\hana-jdbc-2.0.9.jar;D:\MyDemoSoft\Maven\repos\org\postgresql\postgresql\42.2.2\postgresql-42.2.2.jar;D:\MyDemoSoft\Maven\repos\org\slf4j\slf4j-api\1.7.21\slf4j-api-1.7.21.jar;D:\MyDemoSoft\Maven\repos\ch\qos\logback\logback-core\1.1.7\logback-core-1.1.7.jar;D:\MyDemoSoft\Maven\repos\ch\qos\logback\logback-classic\1.1.7\logback-classic-1.1.7.jar;D:\MyDemoSoft\Maven\repos\ch\qos\logback\logback-access\1.1.7\logback-access-1.1.7.jar;D:\MyDemoSoft\Maven\repos\commons-lang\commons-lang\2.6\commons-lang-2.6.jar;D:\MyDemoSoft\Maven\repos\org\apache\commons\commons-lang3\3.4\commons-lang3-3.4.jar;D:\MyDemoSoft\Maven\repos\commons-codec\commons-codec\1.10\commons-codec-1.10.jar;D:\MyDemoSoft\Maven\repos\com\sap\liquibase-hana\3.1\liquibase-hana-3.1.jar;D:\MyDemoSoft\Maven\repos\org\springframework\spring-core\4.3.11.RELEASE\spring-core-4.3.11.RELEASE.jar;D:\MyDemoSoft\Maven\repos\org\springframework\spring-beans\4.3.11.RELEASE\spring-beans-4.3.11.RELEASE.jar;D:\MyDemoSoft\Maven\repos\org\springframework\spring-context\4.3.11.RELEASE\spring-context-4.3.11.RELEASE.jar;D:\MyDemoSoft\Maven\repos\org\springframework\spring-aop\4.3.11.RELEASE\spring-aop-4.3.11.RELEASE.jar;D:\MyDemoSoft\Maven\repos\org\springframework\spring-expression\4.3.11.RELEASE\spring-expression-4.3.11.RELEASE.jar;D:\MyDemoSoft\Maven\repos\org\apache\cxf\cxf-rt-transports-http\3.1.7\cxf-rt-transports-http-3.1.7.jar;D:\MyDemoSoft\Maven\repos\org\apache\poi\poi\3.16\poi-3.16.jar;D:\MyDemoSoft\Maven\repos\org\apache\commons\commons-collections4\4.1\commons-collections4-4.1.jar;D:\MyDemoSoft\Maven\repos\org\apache\poi\poi-ooxml\3.16\poi-ooxml-3.16.jar;D:\MyDemoSoft\Maven\repos\org\apache\poi\poi-ooxml-schemas\3.16\poi-ooxml-schemas-3.16.jar;D:\MyDemoSoft\Maven\repos\org\apache\xmlbeans\xmlbeans\2.6.0\xmlbeans-2.6.0.jar;D:\MyDemoSoft\Maven\repos\stax\stax-api\1.0.1\stax-api-1.0.1.jar;D:\MyDemoSoft\Maven\repos\com\github\virtuald\curvesapi\1.04\curvesapi-1.04.jar;D:\MyDemoSoft\Maven\repos\javax\servlet\javax.servlet-api\3.1.0\javax.servlet-api-3.1.0.jar;D:\MyDemoSoft\Maven\repos\org\springframework\spring-messaging\4.3.11.RELEASE\spring-messaging-4.3.11.RELEASE.jar;D:\MyDemoSoft\Maven\repos\com\hand\hap-job\3.5.4.1-RELEASE\hap-job-3.5.4.1-RELEASE.war;D:\MyDemoSoft\Maven\repos\com\hand\hap-task\3.5.4.1-RELEASE\hap-task-3.5.4.1-RELEASE.war;D:\MyDemoSoft\Maven\repos\com\hand\hap-report\3.5.4.1-RELEASE\hap-report-3.5.4.1-RELEASE.war;D:\MyDemoSoft\Maven\repos\org\fusesource\hawtdispatch\hawtdispatch-transport\1.22\hawtdispatch-transport-1.22.jar;D:\MyDemoSoft\Maven\repos\org\fusesource\hawtdispatch\hawtdispatch\1.22\hawtdispatch-1.22.jar;D:\MyDemoSoft\Maven\repos\org\fusesource\hawtbuf\hawtbuf\1.11\hawtbuf-1.11.jar;D:\MyDemoSoft\Maven\repos\org\osgi\org.osgi.core\4.2.0\org.osgi.core-4.2.0.jar;D:\MyDemoSoft\Maven\repos\com\google\code\gson\gson\2.8.2\gson-2.8.2.jar;D:\MyDemoSoft\Maven\repos\com\hand\hap-mail\3.5.4.1-RELEASE\hap-mail-3.5.4.1-RELEASE.war;D:\MyDemoSoft\Maven\repos\junit\junit\4.12\junit-4.12.jar;D:\MyDemoSoft\Maven\repos\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;D:\MyDemoSoft\Maven\repos\org\apache\axis\axis\1.4\axis-1.4.jar;D:\MyDemoSoft\Maven\repos\javax\xml\rpc\javax.xml.rpc-api\1.1.2\javax.xml.rpc-api-1.1.2.jar;D:\MyDemoSoft\Maven\repos\commons-discovery\commons-discovery\0.5\commons-discovery-0.5.jar;D:\MyDemoSoft\Maven\repos\commons-logging\commons-logging\1.1.1\commons-logging-1.1.1.jar;D:\MyDemoSoft\Maven\repos\wsdl4j\wsdl4j\1.6.2\wsdl4j-1.6.2.jar;D:\MyDemoSoft\Maven\repos\org\apache\cxf\cxf-rt-transports-http-jetty\3.1.7\cxf-rt-transports-http-jetty-3.1.7.jar;D:\MyDemoSoft\Maven\repos\org\apache\cxf\cxf-core\3.1.7\cxf-core-3.1.7.jar;D:\MyDemoSoft\Maven\repos\org\codehaus\woodstox\woodstox-core-asl\4.4.1\woodstox-core-asl-4.4.1.jar;D:\MyDemoSoft\Maven\repos\org\codehaus\woodstox\stax2-api\3.1.4\stax2-api-3.1.4.jar;D:\MyDemoSoft\Maven\repos\org\apache\ws\xmlschema\xmlschema-core\2.2.1\xmlschema-core-2.2.1.jar;D:\MyDemoSoft\Maven\repos\org\eclipse\jetty\jetty-server\9.2.15.v20160210\jetty-server-9.2.15.v20160210.jar;D:\MyDemoSoft\Maven\repos\org\eclipse\jetty\jetty-util\9.2.15.v20160210\jetty-util-9.2.15.v20160210.jar;D:\MyDemoSoft\Maven\repos\org\eclipse\jetty\jetty-io\9.2.15.v20160210\jetty-io-9.2.15.v20160210.jar;D:\MyDemoSoft\Maven\repos\org\eclipse\jetty\jetty-security\9.2.15.v20160210\jetty-security-9.2.15.v20160210.jar;D:\MyDemoSoft\Maven\repos\org\eclipse\jetty\jetty-continuation\9.2.15.v20160210\jetty-continuation-9.2.15.v20160210.jar;D:\MyDemoSoft\Maven\repos\org\eclipse\jetty\jetty-http\9.2.15.v20160210\jetty-http-9.2.15.v20160210.jar;D:\MyDemoSoft\Maven\repos\org\apache\httpcomponents\httpclient\4.5.9\httpclient-4.5.9.jar;D:\MyDemoSoft\Maven\repos\org\apache\httpcomponents\httpcore\4.4.11\httpcore-4.4.11.jar;D:\MyDemoSoft\Maven\repos\com\thoughtworks\xstream\xstream\1.4.8\xstream-1.4.8.jar;D:\MyDemoSoft\Maven\repos\xmlpull\xmlpull\1.1.3.1\xmlpull-1.1.3.1.jar;D:\MyDemoSoft\Maven\repos\xpp3\xpp3_min\1.1.4c\xpp3_min-1.1.4c.jar;D:\MyDemoSoft\Maven\repos\cn\hutool\hutool-all\5.4.2\hutool-all-5.4.2.jar;D:\MyDemoSoft\Maven\repos\jfree\jfreechart\1.0.13\jfreechart-1.0.13.jar;D:\MyDemoSoft\Maven\repos\jfree\jcommon\1.0.16\jcommon-1.0.16.jar;D:\MyDemoSoft\Maven\repos\org\springframework\kafka\spring-kafka\2.1.14.RELEASE\spring-kafka-2.1.14.RELEASE.jar;D:\MyDemoSoft\Maven\repos\org\springframework\spring-tx\5.0.15.RELEASE\spring-tx-5.0.15.RELEASE.jar;D:\MyDemoSoft\Maven\repos\org\springframework\retry\spring-retry\1.2.4.RELEASE\spring-retry-1.2.4.RELEASE.jar;D:\MyDemoSoft\Maven\repos\org\apache\kafka\kafka-clients\1.0.2\kafka-clients-1.0.2.jar;D:\MyDemoSoft\Maven\repos\org\lz4\lz4-java\1.4\lz4-java-1.4.jar;D:\MyDemoSoft\Maven\repos\org\xerial\snappy\snappy-java\1.1.4\snappy-java-1.1.4.jar;D:\MyDemoSoft\Maven\repos\org\mapstruct\mapstruct\1.5.2.Final\mapstruct-1.5.2.Final.jar;D:\MyDemoSoft\Maven\repos\org\mapstruct\mapstruct-processor\1.5.2.Final\mapstruct-processor-1.5.2.Final.jar;D:\MyDemoSoft\IntelliJ IDEA 2022.1.2\lib\idea_rt.jar" calb_les.les_api.calb_les_invoke.controllers.Test
Connected to the target VM, address: '127.0.0.1:51465', transport: 'socket'
未转义:[{"materialLot":"3","lot":"2","locator":"1"}]
转义后:[{\\\"materialLot\\\":\\\"3\\\",\\\"lot\\\":\\\"2\\\",\\\"locator\\\":\\\"1\\\"}]
反转义后:[{"materialLot":"3","lot":"2","locator":"1"}]
Disconnected from the target VM, address: '127.0.0.1:51465', transport: 'socket'

Process finished with exit code 0

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值