安卓解析之 -gson

时间:2021-10-01 22:35:07

gson解析比较方便、代码量少、方便;

gson解析之解析集合:

Gson gson = new Gson();
Type type = new TypeToken<ArrayList<Topic>>() {
}.getType();
List<Topic> topics = gson.fromJson(s, type);
gson解析类:

Gson gson= GsonBuilderUtil.create();
PersonInfo personInfo=gson.fromJson(S,PersonInfo.class);

gson解析(集合、字符串等)

 Gson gson = GsonBuilderUtil.create();
LaunchTopic topics = gson.fromJson(S,LaunchTopic.class);

public class LaunchTopic {
private List<Topic> topics;
private int state;
private String s;
}