コード例 #1
0
  @Override
  public int parseJson(JSONObject json) {
    // TODO Auto-generated method stub
    try {
      id = json.getString("id");

      JSONObject fromObject = json.getJSONObject("from");
      from = new From(fromObject.getString("id"), fromObject.getString("name"));

      createdTime = json.getString("created_time");

      JSONObject applicationObject = json.getJSONObject("application");
      application =
          new From(applicationObject.getString("id"), applicationObject.getString("name"));

      achievement = new Achievement();
      JSONObject achiveObject = json.getJSONObject("achivement");
      achievement.setId(achiveObject.getString("id"));
      achievement.setUrl(achiveObject.getString("url"));
      achievement.setType(achiveObject.getString("type"));
      achievement.setTitle(achiveObject.getString("title"));

      likes = new Like();
      JSONObject likeObject = json.getJSONObject("likes");
      JSONArray likeArray = likeObject.getJSONArray("data");
      ArrayList<From> likeList = new ArrayList<From>(likeObject.getInt("count"));
      for (int i = 0; i < likeObject.getInt("count"); i++) {
        likeList.add(
            new From(
                likeArray.getJSONObject(i).getString("id"),
                likeArray.getJSONObject(i).getString("name")));
      }
      likes = new Like(likeList, likeObject.getInt("count"));

      comments = new ArrayList<Comment>();
      JSONObject commentObject = json.getJSONObject("comments");
      JSONArray commentArray = commentObject.getJSONArray("data");
      for (int i = 0; i < commentObject.getInt("count"); i++) {
        Comment tmp = new Comment();
        tmp.setId(commentArray.getJSONObject(i).getString("id"));
        tmp.setFrom(
            new From(
                commentArray.getJSONObject(i).getJSONObject("from").getString("id"),
                commentArray.getJSONObject(i).getJSONObject("from").getString("name")));
        tmp.setMessage(commentArray.getJSONObject(i).getString("message"));
        tmp.setCreateTime(commentArray.getJSONObject(i).getString("created_time"));
        comments.add(tmp);
      }

    } catch (JSONException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    return 0;
  }