阿里巴巴 JSONObject.toJSONString 刪除轉義字符

在fastjson-1.2.12版本中,JSONField支持一個新的配置項jsonDirect,它的用途是:當你有一個字段是字符串類型,裏面是json格式數據,你希望直接輸入,而不是經過轉義之後再輸出。

Model

import com.alibaba.fastjson.annotation.JSONField;

public static class Model {
    public int id;
    @JSONField(jsonDirect=true)
    public String value;
}

Usage

Model model = new Model();
model.id = 1001;
model.value = "{}";

String json = JSON.toJSONString(model);
Assert.assertEquals("{\"id\":1001,\"value\":{}}", json);

 

原文:https://github.com/alibaba/fastjson/wiki/JSONField_jsonDirect_cn

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章