- 使用fastjson的Json.toJsonString方法时出现多余反斜杠json
{"data":"{"models":[{"name":"test","id":1}],"table":"ws"}","option":"add"}
- 使用 StringEscapeUtils.unescapeJavaScript(jsDataStr) 解决!!
{"data":"{"models":[{"name":"test","id":1}],"table":"ws"}","option":"add"}
- json字符串转json
JSONObject.parseObject(reqdata)
- StringEscapeUtils 属于 org.apache.commons.lang 包下
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
- 测试
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"}]
}