我將"this\'s my case!"
設置爲對象的字段。如何避免傑克遜逃避反斜槓?
調用writeAsString
,輸出是"this\\\'s my case!"
。我想期待"this\'s my case!"
。
我怎樣才能得到我想要的?
public class CommonUtils {
public static ObjectMapper objectMapper = new ObjectMapper();
public static ObjectMapper getObjectMapperInstance(){
return objectMapper;
}
public static void main(String[] args) throws IOException {
CommonUtils commonUtils = new CommonUtils();
commonUtils.test();
}
public void test() throws IOException {
List<MyObject> list = new ArrayList<MyObject>();
String xx = "page://list?params={\"city\"}";
list.add(new MyObject(1,xx));
}
class MyObject{
public MyObject(int tag,String str){
this.tag = tag;
this.str = str;
}
int tag;
String str;
public int getTag() {
return tag;
}
public void setTag(int tag) {
this.tag = tag;
}
public String getStr() {
return str;
}
public void setStr(String str) {
this.str = str;
}
}
}
輸出的上面的代碼:
[{ 「標籤」:1, 「STR」: 「頁://列表PARAMS = {\\?」 城市\\「}]
我要的是: [{ 「標籤」:1, 「STR」: 「頁面://列表PARAMS = {\」 城\「}]
你得到的輸出有什麼問題。我沒有得到 –