[Android] 使用GSON解析json成Bean

解析jsonObject

JSONObject data = jsonObject.getJSONObject("data");
Gson gson = new Gson();
Type type = new TypeToken<Bean>(){}.getType();
Bean bean = gson.fromJson(String.valueOf(data), type);

解析JSONArray 

JSONArray array = jsonObject.getJSONArray("data");
Gson gson = new Gson();
Type type = new TypeToken<List<Bean>>() {}.getType();
List list = gson.fromJson(String.valueOf(array), type);

 

posted @ 2018-04-17 16:17  NOIP/NOI辅导  Views(1263)  Comments(0Edit  收藏  举报