wzk-0000
String、JsonObject、JavaBean 互相转换
    User user = new Gson().fromJson(jsonObject, User.class);
    User user = new Gson().fromJson(string, User.class);
    String string = new Gson().toJson(user);
    JsonObject jsonObject = new Gson().toJsonTree(user).getAsJsonObject(); 
    JsonObject jsonObject = new JsonParser().parse(string).getAsJsonObject();
String、JsonArray、List互相转换
  Type type =new TypeToken<List<User>>() {
  }.getType()
;

  List<User> userList = gson.fromJson(string, type);
  List<User> userList = gson.fromJson(jsonArray, type);

  String string = new Gson().toJson(userList);
  JsonArray jsonArray = new Gson().toJsonTree(userList, type).getAsJsonArray();
  JsonArray jsonArray = new JsonParser().parse(string).getAsJsonArray();

分类:

技术点:

相关文章:

  • 2021-12-27
  • 2021-11-18
  • 2021-11-28
  • 2021-10-11
  • 2021-11-18
  • 2021-11-18
  • 2021-11-18
猜你喜欢
  • 2021-11-18
  • 2021-11-18
  • 2021-11-18
  • 2021-11-28
  • 2021-11-28
  • 2021-11-18
  • 2021-11-18
相关资源
相似解决方案