1、String转Json
- JSONObject json = JSONObject.fromObject(str);
- json.has(“aaa”)
- json.remove(“aaa”);
2、Json转String
- gson.toJson(json)
3、对象转Json
- @JsonInclude(JsonInclude.Include.NON_NULL) :意在实体类与json互转的时候,属性值为null的不参与序列化。慎用。
3、Json转对象
Gson gson = new GsonBuilder().setDateFormat(“yyyy-MM-dd HH:mm:ss”).create();
AddFormQueryCondition addFormQueryConditon = gson.fromJson(gson.toJson(json), AddFormQueryCondition.class);
Gson gson = new GsonBuilder().serializeNulls().setDateFormat(“yyyy-MM-dd HH:mm:ss”).create();
String strJson = gson.toJson(resultMap);