List of usage examples for org.json JSONObject getJSONArray
public JSONArray getJSONArray(String key) throws JSONException
From source file:org.eclipse.orion.server.tests.servlets.git.GitStashTest.java
@Test public void testStashDrop() throws Exception { String projectName = getMethodName(); createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME); JSONObject project = createProjectOrLink(workspaceLocation, projectName, gitDir.toString()); JSONObject testTxt = getChild(project, "test.txt"); //$NON-NLS-1$ modifyFile(testTxt, "change to stash"); //$NON-NLS-1$ String stashLocation = getStashLocation(project); ServerStatus status = createStash(stashLocation); assertTrue(status.isOK());//from w w w . j ava 2 s .c o m status = getStashList(stashLocation); assertTrue(status.isOK()); JSONObject stash = status.getJsonData(); assertTrue(stash.has(ProtocolConstants.KEY_CHILDREN)); assertEquals(1, stash.getJSONArray(ProtocolConstants.KEY_CHILDREN).length()); JSONObject change = stash.getJSONArray(ProtocolConstants.KEY_CHILDREN).getJSONObject(0); assertTrue(change.has(GitConstants.KEY_STASH_DROP_LOCATION)); status = dropStash(change.getString(GitConstants.KEY_STASH_DROP_LOCATION)); assertTrue(status.isOK()); status = getStashList(stashLocation); assertTrue(status.isOK()); stash = status.getJsonData(); assertTrue(stash.has(ProtocolConstants.KEY_CHILDREN)); assertEquals(0, stash.getJSONArray(ProtocolConstants.KEY_CHILDREN).length()); }
From source file:org.eclipse.orion.server.tests.servlets.git.GitDiffTest.java
private String findDiffLocationForBranchByName(String gitBranchUri, String branchName) throws IOException, SAXException, JSONException { JSONObject branches = listBranches(gitBranchUri); JSONArray branchesArray = branches.getJSONArray(ProtocolConstants.KEY_CHILDREN); for (int i = 0; i < branchesArray.length(); i++) { if (branchesArray.getJSONObject(i).getString(ProtocolConstants.KEY_NAME).equals(branchName)) return branchesArray.getJSONObject(i).getString(GitConstants.KEY_DIFF); }//ww w.j a v a2s.c o m fail(NLS.bind("Could not find branch: {0}", branchName)); return null; }
From source file:org.eclipse.orion.server.tests.servlets.git.GitDiffTest.java
private String getDiffCachedLocation(JSONObject fileObject) throws JSONException, IOException, SAXException { // cannot get status on a file // request the status on parent String fileLocation = fileObject.getString(ProtocolConstants.KEY_LOCATION); WebRequest request = getGetRequest(fileLocation + "?parts=meta"); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); JSONObject fileMetaObject = new JSONObject(response.getText()); JSONArray parents = fileMetaObject.getJSONArray(ProtocolConstants.KEY_PARENTS); JSONObject parentObject = parents.getJSONObject(0); request = getGetRequest(parentObject.getString(ProtocolConstants.KEY_LOCATION)); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); parentObject = new JSONObject(response.getText()); request = getGetGitStatusRequest(//from www .ja va 2 s .c o m parentObject.getJSONObject(GitConstants.KEY_GIT).getString(GitConstants.KEY_STATUS)); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); JSONObject statusResponse = new JSONObject(response.getText()); // find entry for the file JSONArray changed = statusResponse.getJSONArray(GitConstants.KEY_STATUS_CHANGED); for (int i = 0; i < changed.length(); i++) { JSONObject changedEntry = changed.getJSONObject(i); if (changedEntry.getString(ProtocolConstants.KEY_NAME) .equals(fileObject.getString(ProtocolConstants.KEY_NAME))) { return changedEntry.getJSONObject(GitConstants.KEY_GIT).getString(GitConstants.KEY_DIFF); } } fail(NLS.bind("Diff Cached Location for {0}, could not be found", fileObject.getString(ProtocolConstants.KEY_NAME))); return null; }
From source file:com.github.irib_examples.Act_NetworkListView.java
private Response.Listener<JSONObject> createMyReqSuccessListener() { return new Response.Listener<JSONObject>() { @Override/*from www .j a v a2 s . c o m*/ public void onResponse(JSONObject response) { try { JSONObject feed = response.getJSONObject("feed"); JSONArray entries = feed.getJSONArray("entry"); JSONObject entry; for (int i = 0; i < entries.length(); i++) { entry = entries.getJSONObject(i); String url = null; JSONObject media = entry.getJSONObject("media$group"); if (media != null && media.has("media$thumbnail")) { JSONArray thumbs = media.getJSONArray("media$thumbnail"); if (thumbs != null && thumbs.length() > 0) { url = thumbs.getJSONObject(0).getString("url"); } } mEntries.add(new PicasaEntry(entry.getJSONObject("title").getString("$t"), url)); } mAdapter.notifyDataSetChanged(); } catch (JSONException e) { showErrorDialog(); } } }; }
From source file:ssc.SenseSmartCity.java
/** * Take a response object and return response array. The response object is * the raw JSON data retrieved from SSC server. It contain a key and a value. * Here the value is assumed to be an array. * /* w w w . j av a 2s . c o m*/ * @param data Raw JSON object from SSC server * * @return A JSON array containing the requested data * * @throws SSCException.MalformedData if data is not extractable */ private JSONArray responseArray(String data) { JSONArray data_array; try { JSONObject response = new JSONObject(data); data_array = response.getJSONArray(SSCResources.Query.RESPONSE); } catch (org.json.JSONException e) { throw new SSCException.MalformedData(e); } return data_array; }
From source file:ssc.SenseSmartCity.java
/** * Parse a JSON object for sensor readings. A list of sensors is needed to * verify and link sensor and readings together. * //from ww w . j a va2 s .c o m * @param sensors List of Sensors * @param data A JSON object with sensor readings * * @return A map with Sensors as keys and list of readings as values * * @throws SSCException.MalformedData if data is not extractable */ private Map<Sensor, List<SnowPressure>> parseSnowPressureData(List<Sensor> sensors, JSONObject data) { Map<Sensor, List<SnowPressure>> readings = new HashMap<Sensor, List<SnowPressure>>(); Iterator<Sensor> i = sensors.iterator(); try { while (i.hasNext()) { Sensor sensor = i.next(); JSONArray fields = data.getJSONArray(sensor.getSerial()); List<SnowPressure> snowdata = SnowPressure.getSnowPressure(sensor.getSerial(), fields); readings.put(sensor, snowdata); } } catch (org.json.JSONException e) { throw new SSCException.MalformedData(e); } return readings; }
From source file:org.ryancutter.barcajolt.BarcaJolt.java
/** * Find all databases user has access to. Username must have admin access to see this info. * //from w w w .ja va 2s .c o m * @return JSONArray Results of GET operation showing array of database names. Returns null * for any HTTP status code other than 200. */ public JSONArray getDBs() { JSONObject jObject = this.get("/_all_dbs", true); JSONArray jArray = null; // since Cloudant returns a JSONArray rather than JSONObject for /_all_dbs requests, this // class temporarily wraps the array like {"dbs":["database1", "database2"]} if (jObject != null) { try { jArray = jObject.getJSONArray("dbs"); } catch (JSONException e) { Log.e(TAG, "JSONException converting Object to Array", e); } } else { return null; } return jArray; }
From source file:org.ryancutter.barcajolt.BarcaJolt.java
/** * read "rows" array from JSONObject returned by view request * /*from w ww . j av a 2s . c o m*/ * @param jObject JSONObject returned by view request * * @return JSONArray Array stored in "rows". Returns null if not found. */ public static JSONArray getRows(JSONObject jObject) { JSONArray rows = null; try { rows = jObject.getJSONArray("rows"); } catch (JSONException e) { Log.e(TAG, "JSONException while looking for 'rows'", e); } return rows; }
From source file:de.kasoki.jfeedly.JFeedly.java
/** * Search feeds by a specified search query. This will not search in streams. * @param query search query (e.g. "android", "java", etc.) * @param numberOfFeeds Specifiy a maximum number of feeds which will be returned (Default: 20). * @return A list of feeds which are somehow affected by your search query. *///w w w .j ava 2s . c o m public ArrayList<Feed> searchFeeds(String query, int numberOfFeeds) { String response = httpHelper.sendGetRequestToFeedly("/v3/search/feeds/?q=" + query + "&n=" + numberOfFeeds); JSONObject searchResult = new JSONObject(response); JSONArray results = searchResult.getJSONArray("results"); ArrayList<Feed> feeds = new ArrayList<Feed>(); for (int i = 0; i < results.length(); i++) { JSONObject result = results.getJSONObject(i); feeds.add(this.getFeedById(result.getString("feedId"))); } return feeds; }
From source file:de.kasoki.jfeedly.JFeedly.java
/** Returns the number of unread articles for an ID (may be a feed, subscription, category or tag */ protected int getCountOfUnreadArticles(String id) { String response = httpHelper.sendGetRequestToFeedly("/v3/markers/counts"); JSONObject object = new JSONObject(response); JSONArray unreadcounts = object.getJSONArray("unreadcounts"); int unreadCount = -1; for (int i = 0; i < unreadcounts.length(); i++) { JSONObject unread = unreadcounts.getJSONObject(i); String unreadId = unread.getString("id"); if (id.equals(unreadId)) { unreadCount = unread.getInt("count"); break; }/* w ww . java 2 s . com*/ } if (unreadCount == -1) { System.err.println("Unkown id: " + id); } return unreadCount; }