OkHttpClient okHttpClient = new OkHttpClient();
Request request = new Request.Builder().url("http://top.baidu.com/mobile_v2/buzz/hotspot").build();
try {
Response response = okHttpClient.newCall(request).execute();
ArrayList<NewsContent> newss = new ArrayList<>();
JsonObject a = JsonParser.parseString(response.body().string()).getAsJsonObject();
JsonElement result = a.get("result").getAsJsonObject().get("descs");
JsonArray jsonArray = result.getAsJsonArray();
for (JsonElement newContent : jsonArray) {
NewsContent newsContent = new Gson().fromJson(newContent.getAsJsonObject().get("content").getAsJsonObject().get("data").getAsJsonArray().get(0).toString(), NewsContent.class);
newss.add(newsContent);
Log.d("标题", newsContent.getTitle());
}
} catch (IOException e) {
e.printStackTrace();
}
评论 (0)