• java json转义问题(消除反斜杠 etc)


    1. 使用fastjson的Json.toJsonString方法时出现多余反斜杠json

      {"data":"{"models":[{"name":"test","id":1}],"table":"ws"}","option":"add"}

    2. 使用 StringEscapeUtils.unescapeJavaScript(jsDataStr) 解决!!

      {"data":"{"models":[{"name":"test","id":1}],"table":"ws"}","option":"add"}

    3. json字符串转json

      JSONObject.parseObject(reqdata)

    4. StringEscapeUtils 属于 org.apache.commons.lang 包下
    <dependency>
        <groupId>commons-lang</groupId>
        <artifactId>commons-lang</artifactId>
        <version>2.6</version>
    </dependency> 
    

    1. 测试
    public static void main(String[] args) {
        String str = "[{\"uuid\":\"HMpGWayE\",\"name\":\"628c38386e8834bd37d041ce\",\"compareType\":\"01\",\"inputContent\":\"100\",\"tableId\":\"PPNqGqDT$microservice$TABLE$act_id_group\",\"tableName\":\"act_id_group\",\"contentType\":\"\",\"bracketLeft\":\"01\",\"bracketRight\":\"01\"},{\"uuid\":\"P528PQKL\",\"name\":\"628c38386e8834bd37d041d0\",\"compareType\":\"03\",\"inputContent\":\"200\",\"tableId\":\"PPNqGqDT$microservice$TABLE$act_id_group\",\"tableName\":\"act_id_group\",\"contentType\":\"01\",\"bracketLeft\":\"01\",\"bracketRight\":\"01\"}]";
        String javaScript = StringEscapeUtils.unescapeJavaScript(str);
        System.out.println(javaScript);
        // TODO 输出:[{"uuid":"HMpGWayE","name":"628c38386e8834bd37d041ce","compareType":"01","inputContent":"100","tableId":"PPNqGqDT$microservice$TABLE$act_id_group","tableName":"act_id_group","contentType":"","bracketLeft":"01","bracketRight":"01"},{"uuid":"P528PQKL","name":"628c38386e8834bd37d041d0","compareType":"03","inputContent":"200","tableId":"PPNqGqDT$microservice$TABLE$act_id_group","tableName":"act_id_group","contentType":"01","bracketLeft":"01","bracketRight":"01"}]
    }
    
  • 相关阅读:
    html iframe 滚动条
    Angular-Ant Desigin 开篇
    端口访问不了的原因
    swift 加载 本地html 和 网络路径
    xcode9.4 报错 error:The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.
    viewDidLoad, viewWillDisappear, viewWillAppear等区别及各自的加载顺序
    JavaScript设计模式之一Interface接口
    ES6原生Class
    react portals
    react-native-pushy 热更新
  • 原文地址:https://www.cnblogs.com/Twittery/p/16352301.html
Copyright © 2020-2023  润新知