FastJSON等工具序列化特殊字符时会加转义字符\
在Java中JSON数据格式用String接收时,此时在FastJSON层面看来该JSON只是普通字符串,所以对原字符串序列化会得到转义字符\ 得到转义后字符串,再反序列化转义后字符串会得到原字符串
String json="{\"name\": \"张三\", \"age\": 25, \"isStudent\": true}";//代表{"name": "张三", "age": 25, "isStudent": true}String jsonStr="\"{\\\"name\\\": \\\"张三\\\", \\\"age\\\": 25, \\\"isStudent\\\": true}\"";//代表"{\"name\": \"张三\", \"age\": 25, \"isStudent\": true}"String jsonStr2 = JSONObject.toJSONString(json);String json2 = JSONObject.parseObject(jsonStr2, String.class);String json3 = JSONObject.parseObject(json2, String.class);int v=1;
结果
注意图中不要与FastJSON层面的转义字符和java源码层面的转义字符搞混