Home Article Practice 解析数据

解析数据

2022-01-18 11:11  views:451  source:小键人4299743    

//Json的解析类对象
JsonParser parser = new JsonParser();
//将JSON的String 转成一个JsonArray对象
JsonArray jsonArray1 = parser.parse(str).getAsJsonArray();
Gson gson = new Gson();
ArrayList<Sports> userBeanList = new ArrayList<>();
// 加强for循环遍历JsonArray
for (JsonElement user : jsonArray1) {
//使用GSON,直接转成Bean对象
Sports userBean = gson.fromJson(user, Sports.class);
userBeanList.add(userBean);
}
mMyAdapter = new MyAdapter3(getContext(),userBeanList);
mListView.setAdapter(mMyAdapter);



Disclaimer: The above articles are added by users themselves and are only for typing and communication purposes. They do not represent the views of this website, and this website does not assume any legal responsibility. This statement is hereby made! If there is any infringement of your rights, please contact us promptly to delete it.

字符:    改为:
去打字就可以设置个性皮肤啦!(O ^ ~ ^ O)