JsonObject 对象的各种转换:

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互相转换

List userList = gson.fromJson(string, new TypeToken<List>() {}.getType());

List userList = gson.fromJson(jsonArray, new TypeToken<List>() {}.getType());

String string = new Gson().toJson(userList);

JsonArray jsonArray = new Gson().toJsonTree(userList, new TypeToken<List>() {}.getType()).getAsJsonArray();

JsonArray jsonArray = new JsonParser().parse(string).getAsJsonArray()

根据后端接口获取到的JSON对象:
记录关于Android Gson数据的一些转换,以及自己项目中的实际应用;
赋值:
记录关于Android Gson数据的一些转换,以及自己项目中的实际应用;

相关文章:

  • 2022-12-23
  • 2022-02-12
  • 2022-01-06
  • 2021-12-03
  • 2021-12-05
  • 2023-03-28
  • 2021-09-20
  • 2022-01-18
猜你喜欢
  • 2021-10-21
  • 2021-04-14
  • 2021-09-07
  • 2021-12-03
  • 2021-10-24
  • 2022-02-07
  • 2022-02-07
相关资源
相似解决方案