List of usage examples for org.json JSONArray getJSONObject
public JSONObject getJSONObject(int index) throws JSONException
From source file:com.piggate.sdk.PiggateInfo.java
private static void registryInfo(JSONArray offers) { ArrayList<PiggateInfo> listaOffers = new ArrayList<PiggateInfo>(); for (int x = 0; x < offers.length(); x++) { try {//w w w . ja v a 2 s . co m listaOffers.add(new PiggateInfo(offers.getJSONObject(x))); } catch (JSONException e) { } } registryInfo(listaOffers); }
From source file:com.creationgroundmedia.popularmovies.trailers.TrailerLoader.java
private List<TrailerItem> getTrailersFromJSON(String trailersJsonStr) throws JSONException { if (trailersJsonStr == null) { return null; }//from w w w .j a v a2 s. co m JSONObject movieJSON = new JSONObject(trailersJsonStr); JSONArray trailersList = movieJSON.getJSONArray(mContext.getString(R.string.jsonresults)); mTrailers = new ArrayList<>(); for (int i = 0; i < trailersList.length(); i++) { JSONObject titleJSON = trailersList.getJSONObject(i); if (titleJSON.getString(mContext.getString(R.string.jsonsite)).equalsIgnoreCase("YouTube")) { TrailerItem t = new TrailerItem(titleJSON.getString(mContext.getString(R.string.jsonname)), titleJSON.getString(mContext.getString(R.string.jsonkey))); mTrailers.add(t); } } return mTrailers; }
From source file:com.miz.service.TraktMoviesSyncService.java
/** * Get movie collection from Trakt//from w ww . j a v a 2 s.c om */ private void downloadMovieCollection() { JSONArray jsonArray = Trakt.getMovieLibrary(this, Trakt.COLLECTION); if (jsonArray.length() > 0) { for (int i = 0; i < jsonArray.length(); i++) { try { mMovieCollection.add(String.valueOf(jsonArray.getJSONObject(i).get("tmdb_id"))); } catch (Exception e) { } } } jsonArray = null; }
From source file:com.miz.service.TraktMoviesSyncService.java
private void downloadWatchedMovies() { JSONArray jsonArray = Trakt.getMovieLibrary(this, Trakt.WATCHED); if (jsonArray.length() > 0) { for (int i = 0; i < jsonArray.length(); i++) { try { String tmdbId = String.valueOf(jsonArray.getJSONObject(i).get("tmdb_id")); mWatchedMovies.add(tmdbId); mMovieDatabase.updateMovieSingleItem(tmdbId, DbAdapterMovies.KEY_HAS_WATCHED, "1"); } catch (Exception e) { }//from www . ja va2s . com } } }
From source file:com.miz.service.TraktMoviesSyncService.java
private void downloadMovieFavorites() { JSONArray jsonArray = Trakt.getMovieLibrary(this, Trakt.RATINGS); if (jsonArray.length() > 0) { for (int i = 0; i < jsonArray.length(); i++) { try { String tmdbId = String.valueOf(jsonArray.getJSONObject(i).get("tmdb_id")); mMovieFavorites.add(tmdbId); mMovieDatabase.updateMovieSingleItem(tmdbId, DbAdapterMovies.KEY_FAVOURITE, "1"); } catch (Exception e) { }//from w w w . ja v a 2 s .co m } } }
From source file:com.miz.service.TraktMoviesSyncService.java
private void downloadWatchlist() { JSONArray jsonArray = Trakt.getMovieLibrary(this, Trakt.WATCHLIST); if (jsonArray.length() > 0) { for (int i = 0; i < jsonArray.length(); i++) { try { String tmdbId = String.valueOf(jsonArray.getJSONObject(i).get("tmdb_id")); mWatchlist.add(tmdbId);//from w w w . java 2s . co m mMovieDatabase.updateMovieSingleItem(tmdbId, DbAdapterMovies.KEY_TO_WATCH, "1"); } catch (Exception e) { } } } }
From source file:com.github.koraktor.steamcondenser.community.GameInventory.java
/** * Updates the contents of the backpack using Steam Web API * * @throws WebApiException on Web API errors *///from w w w. ja v a2 s .co m public void fetch() throws SteamCondenserException { try { Map<String, Object> params = new HashMap<String, Object>(); params.put("SteamID", this.steamId64); JSONObject result = WebApi.getJSONData("IEconItems_" + this.getAppId(), "GetPlayerItems", 1, params); this.items = new HashMap<Integer, GameItem>(); this.preliminaryItems = new ArrayList<GameItem>(); JSONArray itemsData = result.getJSONArray("items"); for (int i = 0; i < itemsData.length(); i++) { JSONObject itemData = itemsData.getJSONObject(i); if (itemData != null) { try { GameItem item = this.getItemClass().getConstructor(this.getClass(), JSONObject.class) .newInstance(this, itemData); if (item.isPreliminary()) { this.preliminaryItems.add(item); } else { this.items.put(item.getBackpackPosition() - 1, item); } } catch (IllegalAccessException e) { } catch (InstantiationException e) { } catch (InvocationTargetException e) { if (e.getCause() instanceof SteamCondenserException) { throw (SteamCondenserException) e.getCause(); } else { throw (RuntimeException) e.getCause(); } } catch (NoSuchMethodException e) { } } } } catch (JSONException e) { throw new WebApiException("Could not parse JSON data.", e); } this.fetchDate = new Date(); }
From source file:com.github.koraktor.steamcondenser.community.SteamId.java
/** * Fetches the friends of this user/*from w w w . jav a2s . c om*/ * <p> * This creates a new <code>SteamId</code> instance for each of the friends * without fetching their data. * * @see #getFriends * @see SteamId#SteamId * @throws SteamCondenserException if an error occurs while parsing the * data */ private void fetchFriends() throws SteamCondenserException { try { Map<String, Object> params = new HashMap<String, Object>(); params.put("relationship", "friend"); params.put("steamid", this.steamId64); JSONObject jsonData = new JSONObject(WebApi.getJSON("ISteamUser", "GetFriendList", 1, params)); JSONArray friendsData = jsonData.getJSONObject("friendslist").getJSONArray("friends"); this.friends = new ArrayList<SteamId>(); for (int i = 0; i < friendsData.length(); i++) { JSONObject friend = friendsData.getJSONObject(i); this.friends.add(new SteamId(friend.getLong("steamid"), false)); } } catch (JSONException e) { throw new WebApiException("Could not parse JSON data.", e); } }
From source file:org.jenkinsci.plugins.testrail.TestRailClient.java
public Project[] getProjects() throws IOException, ElementNotFoundException { String body = httpGet("/index.php?/api/v2/get_projects").getBody(); JSONArray json = new JSONArray(body); Project[] projects = new Project[json.length()]; for (int i = 0; i < json.length(); i++) { JSONObject o = json.getJSONObject(i); Project p = new Project(); p.setName(o.getString("name")); p.setId(o.getInt("id")); projects[i] = p;/*from w ww . ja v a 2s. c om*/ } return projects; }
From source file:org.jenkinsci.plugins.testrail.TestRailClient.java
public Suite[] getSuites(int projectId) throws IOException, ElementNotFoundException { String body = httpGet("/index.php?/api/v2/get_suites/" + projectId).getBody(); JSONArray json; try {//ww w .j a va 2 s. c om json = new JSONArray(body); } catch (JSONException e) { return new Suite[0]; } Suite[] suites = new Suite[json.length()]; for (int i = 0; i < json.length(); i++) { JSONObject o = json.getJSONObject(i); Suite s = new Suite(); s.setName(o.getString("name")); s.setId(o.getInt("id")); suites[i] = s; } return suites; }