Exemplo n.º 1
0
  public static Photo fromJsonSingle(JSONObject jsonObject) {
    Photo b = new Photo();
    // Deserialize json into object fields
    try {
      b.id = jsonObject.getInt("id");
      b.album_id = jsonObject.getInt("album_id");
      b.owner_id = jsonObject.getInt("owner_id");
      b.photo_75 = jsonObject.getString("photo_75");
      b.photo_130 = jsonObject.getString("photo_130");
      // b.photo_604 = jsonObject.getString("photo_604");
      // b.photo_807 = jsonObject.getString("photo_807");//TODO not sure about those photo sizes
      // b.width = jsonObject.getInt("width");
      // b.height = jsonObject.getInt("height");
      // b.text = jsonObject.getString("text");
      // b.access_key = jsonObject.getString("access_key");
      // b.post_source_type = jsonObject.getJSONObject("post_source").getString("type");
      // b.comments_count = jsonObject.getJSONObject("comments").getInt("count");
      // b.likes_count = jsonObject.getJSONObject("likes").getInt("count");
      // b.reposts_count = jsonObject.getJSONObject("reposts").getInt("count");

    } catch (JSONException e) {
      e.printStackTrace();
      Log.e(TAG, "Error processing JSONObject  " + jsonObject.toString());
      return null;
    }
    // Return new object
    return b;
  }
Exemplo n.º 2
0
  public static ArrayList<Photo> fromJson(JSONObject jsonArray) {

    ArrayList<Photo> response = new ArrayList<Photo>(jsonArray.length());
    JSONObject jsonObject = null;
    try {
      items = jsonArray.getJSONObject("response").getJSONArray("items");
      // Process each result in json array, decode and convert to CommunitiesResponseModel object
      for (int i = 0; i < jsonArray.length(); i++) {
        jsonObject = items.getJSONObject(i);

        Photo business = Photo.fromJsonSingle(jsonObject);
        if (business != null) {
          response.add(business);
        }
      }
    } catch (Exception e) {
      Log.e(TAG, "Error processing JSONArray  " + jsonObject.toString());
      e.printStackTrace();
    }
    // Log.e(TAG, "Success with JSONArray  " + response.get(0).getTitle().toString());

    return response;
  }