Ejemplo n.º 1
0
  private void parseItemsByGson(List<GalleryItem> items, String jsonString) {
    JsonObject jsonBody = new JsonParser().parse(jsonString).getAsJsonObject();
    JsonObject photosJsonObject = jsonBody.get("photos").getAsJsonObject();
    JsonArray photosJsonArray = photosJsonObject.get("photo").getAsJsonArray();

    for (int i = 0; i < photosJsonArray.size(); i++) {
      JsonObject photoJsonObject = photosJsonArray.get(i).getAsJsonObject();

      GalleryItem item = new GalleryItem();
      item.setId(photoJsonObject.get("id").getAsString());
      item.setCaption(photoJsonObject.get("title").getAsString());

      if (!photoJsonObject.has("url_s")) {
        continue;
      }

      item.setUrl(photoJsonObject.get("url_s").getAsString());
      item.setOwner(photoJsonObject.get("owner").getAsString());
      items.add(item);
    }
  }
Ejemplo n.º 2
0
  void parseItems(ArrayList<GalleryItem> items, XmlPullParser parser)
      throws XmlPullParserException, IOException {
    int eventType = parser.next();

    while (eventType != XmlPullParser.END_DOCUMENT) {
      if (eventType == XmlPullParser.START_TAG && XML_PHOTO.equals(parser.getName())) {
        String id = parser.getAttributeValue(null, "id");
        String caption = parser.getAttributeValue(null, "title");
        String smallUrl = parser.getAttributeValue(null, EXTRA_SMALL_URL);
        String owner = parser.getAttributeValue(null, "owner");

        GalleryItem item = new GalleryItem();
        item.setmId(id);
        item.setCaption(caption);
        item.setUrl(smallUrl);
        item.setOwner(owner);
        items.add(item);
      }
      eventType = parser.next();
    }
  }
Ejemplo n.º 3
0
  private void parseItems(List<GalleryItem> items, String jsonString)
      throws IOException, JSONException {
    JSONObject jsonBody = new JSONObject(jsonString);
    JSONObject photosJsonObject = jsonBody.getJSONObject("photos");
    JSONArray photosJsonArray = photosJsonObject.getJSONArray("photo");

    for (int i = 0; i < photosJsonArray.length(); i++) {
      JSONObject photoJsonObject = photosJsonArray.getJSONObject(i);

      GalleryItem item = new GalleryItem();
      item.setId(photoJsonObject.getString("id"));
      item.setCaption(photoJsonObject.getString("title"));

      if (!photoJsonObject.has("url_s")) {
        continue;
      }

      item.setUrl(photoJsonObject.getString("url_s"));
      items.add(item);
    }
  }