【MapSheep】
[好记性不如烂笔头]
  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"}]
}
posted on 2022-06-07 16:17  (Play)  阅读(2088)  评论(0编辑  收藏  举报