예제 #1
0
  private List<NewsBean> getJsonData(String url) {
    List<NewsBean> newsBeanList = new ArrayList<>();
    JSONObject jsonObject = null;
    NewsBean newsBean;
    try {
      String jsonString = readStream(new URL(url).openStream());
      jsonObject = new JSONObject(jsonString);
      JSONArray jsonArray = jsonObject.getJSONArray("data");

      for (int i = 0; i < jsonArray.length(); i++) {
        jsonObject = jsonArray.getJSONObject(i);
        newsBean = new NewsBean();
        newsBean.newsIconUrl = jsonObject.getString("picSmall");
        newsBean.newsTitle = jsonObject.getString("name");
        newsBean.newsContent = jsonObject.getString("description");
        newsBeanList.add(newsBean);
      }

    } catch (IOException e) {
      e.printStackTrace();
    } catch (JSONException e) {
      e.printStackTrace();
    }

    return newsBeanList;
  }