String在json格式化后,去掉\转义符

在java中String在toJSonString后会连转义符\一起转,如下图:

 使用如下方式也就是图中的第二种方式,就不会出现转移符。
 

 import org.apache.commons.lang.StringEscapeUtils;

 public static void main(String[] args) {
        CustomerDataDto customerDataDto = new CustomerDataDto();
        customerDataDto.setOther("{\"product_no\":\"JPRI1903041024500001\",\"merchant_no\":\"8808001000321872\"}");
   
        System.out.println(StringEscapeUtils.unescapeJavaScript(JSON.toJSONString(customerDataDto)));
    }

猜你喜欢

转载自blog.csdn.net/lingyancangqiong/article/details/88721976
今日推荐