Create JSON String using GSON

后端 未结 5 2085
梦毁少年i
梦毁少年i 2021-02-05 09:29

I am having a class like following,

public class Student {
    public int id;
    public String name;
    public int age;    
}

Now I want to c

5条回答
  •  耶瑟儿~
    2021-02-05 09:53

    JsonObject jsObj =  (JsonObject) new Gson().toJsonTree(stu2);
    jsObj.remove("age"); // remove field 'age'
    jsObj.addProperty("key", "value"); // add field 'key'
    
    System.out.println(jsObj);
    

    You can manipulate with JsonObject

提交回复
热议问题