使用Gson可以去除Json的某个字段,具体如下
需求:contentBean是个pojo对象,需要去掉id字段。
操作:
Gson gson = new Gson();
//去除id字段
try {
JSONObject jsonObject = new JSONObject(contentGSON);
jsonObject.remove("id");
contentGSON = null;
contentGSON = jsonObject.toString();
} catch (JSONException e) {
e.printStackTrace();
}