List of usage examples for org.json JSONArray get
public Object get(int index) throws JSONException
From source file:com.funzio.pure2D.particles.nova.vo.NovaVO.java
protected static ArrayList<GLColor> getListColor(final JSONObject json, final String field) throws JSONException { // field check if (!json.has(field)) { return null; }/*from w w w .j av a 2 s.c om*/ final ArrayList<GLColor> result = new ArrayList<GLColor>(); try { final JSONArray array = json.getJSONArray(field); if (array != null) { final int size = array.length(); for (int i = 0; i < size; i++) { if (array.get(i) instanceof String) { result.add(new GLColor(Color.parseColor(array.getString(i)))); } else { result.add(new GLColor(array.getInt(i))); } } } } catch (JSONException e) { // single value if (json.get(field) instanceof String) { result.add(new GLColor(Color.parseColor(json.getString(field)))); } else { result.add(new GLColor(json.getInt(field))); } } return result; }
From source file:com.apecat.shoppingadvisor.scan.result.supplement.BookResultInfoRetriever.java
@Override void retrieveSupplementalInfo() throws IOException { CharSequence contents = HttpHelper.downloadViaHttp( "https://www.googleapis.com/books/v1/volumes?q=isbn:" + isbn, HttpHelper.ContentType.JSON); if (contents.length() == 0) { return;// w w w.j a v a 2 s .c om } String title; String pages; Collection<String> authors = null; try { JSONObject topLevel = (JSONObject) new JSONTokener(contents.toString()).nextValue(); JSONArray items = topLevel.optJSONArray("items"); if (items == null || items.isNull(0)) { return; } JSONObject volumeInfo = ((JSONObject) items.get(0)).getJSONObject("volumeInfo"); if (volumeInfo == null) { return; } title = volumeInfo.optString("title"); pages = volumeInfo.optString("pageCount"); JSONArray authorsArray = volumeInfo.optJSONArray("authors"); if (authorsArray != null && !authorsArray.isNull(0)) { authors = new ArrayList<String>(authorsArray.length()); for (int i = 0; i < authorsArray.length(); i++) { authors.add(authorsArray.getString(i)); } } } catch (JSONException e) { throw new IOException(e); } Collection<String> newTexts = new ArrayList<String>(); maybeAddText(title, newTexts); maybeAddTextSeries(authors, newTexts); maybeAddText(pages == null || pages.isEmpty() ? null : pages + "pp.", newTexts); String baseBookUri = "http://www.google." + LocaleManager.getBookSearchCountryTLD(context) + "/search?tbm=bks&source=zxing&q="; append(isbn, source, newTexts.toArray(new String[newTexts.size()]), baseBookUri + isbn); }
From source file:com.melniqw.instagramsdk.Api.java
/** * https://instagram.com/developer/endpoints/users/#get_users_feed */// ww w . j ava 2s.co m public static ArrayList<Media> getSelfFeed(Integer count, Integer minId, Integer maxId, String accessToken) throws IOException, JSONException { Params params = new Params("/users/self/feed"); params.put("count", count); params.put("min_id", minId); params.put("max_id", maxId); params.put("access_token", accessToken); JSONObject rootJSON = Network.sendRequest(Api.API_BASE_URL, params, Network.Request.GET); JSONArray mediaJSONArray = rootJSON.optJSONArray("data"); ArrayList<Media> medias = new ArrayList<>(); for (int i = 0; i < mediaJSONArray.length(); i++) { JSONObject mediaJSON = (JSONObject) mediaJSONArray.get(i); medias.add(Media.fromJSON(mediaJSON)); } return medias; }
From source file:com.melniqw.instagramsdk.Api.java
/** * https://instagram.com/developer/endpoints/users/#get_users_media_recent * @param minTimestamp is a UNIX timestamp * @param maxTimestamp is a UNIX timestamp *//*from ww w . j a va2 s .c o m*/ public static ArrayList<Media> getUserMediaRecent(String userId, Integer count, Integer minId, Integer maxId, Integer minTimestamp, Integer maxTimestamp, String accessToken) throws IOException, JSONException { Params params = new Params("/users/" + userId + "/media/recent"); params.put("count", count); params.put("min_id", minId); params.put("max_id", maxId); params.put("min_timestamp", minTimestamp); params.put("max_timestamp", maxTimestamp); params.put("access_token", accessToken); JSONObject rootJSON = Network.sendRequest(API_BASE_URL, params, Network.Request.GET); JSONArray mediaJSONArray = rootJSON.optJSONArray("data"); ArrayList<Media> medias = new ArrayList<>(); for (int i = 0; i < mediaJSONArray.length(); i++) { JSONObject mediaJSON = (JSONObject) mediaJSONArray.get(i); medias.add(Media.fromJSON(mediaJSON)); } return medias; }
From source file:com.melniqw.instagramsdk.Api.java
/** * https://instagram.com/developer/endpoints/users/#get_users_feed_liked *//*from ww w . j a v a 2 s . c o m*/ public static ArrayList<Media> getSelfMediaLiked(Integer count, Integer maxLikeId, String accessToken) throws IOException, JSONException { Params params = new Params("/users/self/media/liked"); params.put("count", count); params.put("max_like_id", maxLikeId); params.put("access_token", accessToken); JSONObject rootJSON = Network.sendRequest(API_BASE_URL, params, Network.Request.GET); JSONArray mediaJSONArray = rootJSON.optJSONArray("data"); ArrayList<Media> medias = new ArrayList<>(); for (int i = 0; i < mediaJSONArray.length(); i++) { JSONObject mediaJSON = (JSONObject) mediaJSONArray.get(i); medias.add(Media.fromJSON(mediaJSON)); } return medias; }
From source file:com.melniqw.instagramsdk.Api.java
/** * https://instagram.com/developer/endpoints/users/#get_users_search *//*w w w . j a v a2 s. com*/ public static ArrayList<User> getUserSearch(String q, Integer count, String accessToken) throws IOException, JSONException { Params params = new Params("/users/search"); params.put("q", q); params.put("count", count); params.put("access_token", accessToken); JSONObject rootJSON = Network.sendRequest(API_BASE_URL, params, Network.Request.GET); JSONArray userJSONArray = rootJSON.optJSONArray("data"); ArrayList<User> users = new ArrayList<>(); for (int i = 0; i < userJSONArray.length(); i++) { JSONObject userJSON = (JSONObject) userJSONArray.get(i); users.add(User.fromJSON(userJSON)); } return users; }
From source file:com.melniqw.instagramsdk.Api.java
/** * https://instagram.com/developer/endpoints/relationships/#get_users_follows *//* w w w. j av a 2s . c om*/ public static ArrayList<User> getUserFollows(String userId, String accessToken) throws IOException, JSONException { Params params = new Params("/users/" + userId + "/follows"); params.put("access_token", accessToken); JSONObject rootJSON = Network.sendRequest(API_BASE_URL, params, Network.Request.GET); JSONArray userJSONArray = rootJSON.optJSONArray("data"); ArrayList<User> users = new ArrayList<>(); for (int i = 0; i < userJSONArray.length(); i++) { JSONObject userJSON = (JSONObject) userJSONArray.get(i); users.add(User.fromJSON(userJSON)); } return users; }
From source file:com.melniqw.instagramsdk.Api.java
/** * https://instagram.com/developer/endpoints/relationships/#get_users_followed_by */// w ww .j a va 2s . c o m public static ArrayList<User> getUserFollowedBy(String userId, String accessToken) throws IOException, JSONException { Params params = new Params("/users/" + userId + "/followed-by"); params.put("access_token", accessToken); JSONObject rootJSON = Network.sendRequest(API_BASE_URL, params, Network.Request.GET); JSONArray userJSONArray = rootJSON.optJSONArray("data"); ArrayList<User> users = new ArrayList<>(); for (int i = 0; i < userJSONArray.length(); i++) { JSONObject userJSON = (JSONObject) userJSONArray.get(i); users.add(User.fromJSON(userJSON)); } return users; }
From source file:com.melniqw.instagramsdk.Api.java
/** * https://instagram.com/developer/endpoints/relationships/#get_incoming_requests *///from www . jav a 2s . co m public static ArrayList<User> getSelfRequestedBy(String accessToken) throws IOException, JSONException { Params params = new Params("/users/self/requested-by"); params.put("access_token", accessToken); JSONObject rootJSON = Network.sendRequest(API_BASE_URL, params, Network.Request.GET); JSONArray userJSONArray = rootJSON.optJSONArray("data"); ArrayList<User> users = new ArrayList<>(); for (int i = 0; i < userJSONArray.length(); i++) { JSONObject userJSON = (JSONObject) userJSONArray.get(i); users.add(User.fromJSON(userJSON)); } return users; }
From source file:org.wso2.carbon.connector.integration.test.livechat.LivechatConnectorIntegrationTest.java
/** * Negative test case for createAgent method . *//* w ww . ja va 2s .c o m*/ @Test(groups = { "wso2.esb" }, description = "livechat {createAgent} integration test with negative case.") public void testCreateAgentWithNegativeCase() throws IOException, JSONException { esbRequestHeadersMap.put("Action", "urn:createAgent"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_createAgent_negative.json"); JSONArray esbErrorsArray = esbRestResponse.getBody().getJSONArray("errors"); String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/agents/"; RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "POST", apiRequestHeadersMap, "api_createAgent_negative.json"); JSONArray apiErrorsArray = apiRestResponse.getBody().getJSONArray("errors"); Assert.assertEquals(apiRestResponse.getHttpStatusCode(), esbRestResponse.getHttpStatusCode()); Assert.assertEquals(apiErrorsArray.get(0).toString(), esbErrorsArray.get(0).toString()); }