List of usage examples for org.json JSONArray getJSONObject
public JSONObject getJSONObject(int index) throws JSONException
From source file:org.wso2.carbon.connector.integration.test.meetup.boards.BoardsIntegrationTest.java
/** * Test getDiscussions API operation for Mandatory fields. * Expecting Response header '200' and 'id' JSONObject in returned * JSONArray./*from w ww . j a va2 s . c o m*/ * * @throws Exception if test fails. */ @Test(enabled = true, groups = { "wso2.esb" }, description = "Board's getDiscussions operation integration test for Mandatory fields") public void testGetDiscussionsMandatory() throws Exception { String jsonRequestFilePath = pathToRequestsDirectory + "boards_getDiscussions_mandatory.txt"; String methodName = "boards_getDiscussions"; final String jsonString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath); final String proxyFilePath = "file:///" + pathToProxiesDirectory + methodName + ".xml"; String modifiedJsonString = String.format(jsonString, meetupConnectorProperties.getProperty("access_token")); proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath))); try { int responseHeader = ConnectorIntegrationUtil .sendRequestToRetriveHeaders(getProxyServiceURL(methodName), modifiedJsonString); Assert.assertTrue(responseHeader == 200); JSONArray jsonArray = ConnectorIntegrationUtil.sendRequestJSONArray(getProxyServiceURL(methodName), modifiedJsonString); JSONObject jsonObject = jsonArray.getJSONObject(0); Assert.assertTrue(jsonObject.has("id")); } finally { proxyAdmin.deleteProxy(methodName); } }
From source file:org.wso2.carbon.connector.integration.test.meetup.boards.BoardsIntegrationTest.java
/** * Test getDiscussionPosts API operation for Mandatory fields. * Expecting Response header '200' and 'id' JSONObject in returned * JSONArray./*from www. j a v a2s . co m*/ * * @throws Exception if test fails. */ @Test(enabled = true, groups = { "wso2.esb" }, description = "Board's getDiscussionPosts operation integration test for Mandatory fields") public void testGetDiscussionPostsMandatory() throws Exception { String jsonRequestFilePath = pathToRequestsDirectory + "boards_getDiscussionPosts_mandatory.txt"; String methodName = "boards_getDiscussionPosts"; final String jsonString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath); final String proxyFilePath = "file:///" + pathToProxiesDirectory + methodName + ".xml"; String modifiedJsonString = String.format(jsonString, meetupConnectorProperties.getProperty("access_token")); proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath))); try { int responseHeader = ConnectorIntegrationUtil .sendRequestToRetriveHeaders(getProxyServiceURL(methodName), modifiedJsonString); Assert.assertTrue(responseHeader == 200); JSONArray jsonArray = ConnectorIntegrationUtil.sendRequestJSONArray(getProxyServiceURL(methodName), modifiedJsonString); JSONObject jsonObject = jsonArray.getJSONObject(0); Assert.assertTrue(jsonObject.has("id")); } finally { proxyAdmin.deleteProxy(methodName); } }
From source file:org.uiautomation.ios.grid.IOSCapabilitiesMonitor.java
private List<DesiredCapabilities> getNodeCapabilities() { try {/*ww w . jav a 2 s. c o m*/ List<DesiredCapabilities> capabilities = new ArrayList<DesiredCapabilities>(); JSONObject status = getNodeStatusJson(); if (status == null) { return null; } String ios = status.getJSONObject("value").getJSONObject("ios").optString("simulatorVersion"); JSONArray supportedApps = status.getJSONObject("value").getJSONArray("supportedApps"); for (int i = 0; i < supportedApps.length(); i++) { Map<String, Object> capability = new HashMap<String, Object>(); capability.put("maxInstances", "1"); if (ios.isEmpty()) { capability.put("ios", "5.1"); capability.put("browserName", "IOS Device"); capability.put(IOSCapabilities.DEVICE, DeviceType.iphone); } else { capability.put("ios", ios); capability.put("browserName", "IOS Simulator"); } JSONObject app = supportedApps.getJSONObject(i); for (String key : JSONObject.getNames(app)) { if ("locales".equals(key)) { JSONArray loc = app.getJSONArray(key); List<String> locales = new ArrayList<String>(); for (int j = 0; j < loc.length(); j++) { locales.add(loc.getString(j)); } capability.put("locales", locales); } else { Object o = app.get(key); capability.put(key, o); } } capabilities.add(new DesiredCapabilities(capability)); } return capabilities; } catch (Exception e) { return null; } }
From source file:org.springframework.social.showcase.flux.support.FluxImpl.java
@Override public List<String> getProjects() throws Exception { MessageConnector conn = getMessagingConnector(); SingleResponseHandler<List<String>> rh = new SingleResponseHandler<List<String>>(getMessagingConnector(), GET_PROJECTS_RESPONSE) {/* www . j a v a2s .c om*/ @Override protected List<String> parse(String messageType, JSONObject message) throws Exception { //Example message: //{"projects":[ // {"name":"bikok"}, // {"name":"hello-world"} // ], // "username":"kdvolder", // "requestSenderID":"amq.gen-55217jjvJI3cJMF9-DZR4A" //} List<String> projects = new ArrayList<String>(); JSONArray jps = message.getJSONArray("projects"); for (int i = 0; i < jps.length(); i++) { projects.add(jps.getJSONObject(i).getString("name")); } return projects; } }; conn.send(GET_PROJECTS_REQUEST, new JSONObject().put(USERNAME, getUsername())); return rh.awaitResult(); }
From source file:nl.hnogames.domoticz.Domoticz.EventsParser.java
@Override public void parseResult(String result) { try {/* w w w . ja va 2s. c om*/ JSONArray jsonArray = new JSONArray(result); ArrayList<EventInfo> mVars = new ArrayList<>(); if (jsonArray.length() > 0) { for (int i = 0; i < jsonArray.length(); i++) { JSONObject row = jsonArray.getJSONObject(i); mVars.add(new EventInfo(row)); } } if (mVars == null || mVars.size() <= 0) onError(new NullPointerException("No Events devined in Domoticz.")); else varsReceiver.onReceiveEvents(mVars); } catch (JSONException e) { Log.e(TAG, "EventsParser JSON exception"); e.printStackTrace(); varsReceiver.onError(e); } }
From source file:com.hhunj.hhudata.ForegroundService.java
private void handleSearchResults(JSONObject json) { try {//from ww w . j a v a 2s . co m String s = json.toString(); int count = json.getInt("number_of_results"); if (count > 0) { JSONArray results = json.getJSONArray("search_results"); // SearchBookContentsResult.setQuery(queryTextView.getText().toString()); List<SearchBookContentsResult> items = new ArrayList<SearchBookContentsResult>(0); for (int x = 0; x < count; x++) { JSONObject sr = results.getJSONObject(x); if (sr != null) { items.add(parseResult(sr)); } } // ... // ,... String message = updatedb(items); if (message != "") { // ... Log.w(TAG, "over time err--------"); sendSMS(m_address + ": " + message + "over time"); } //.... m_httpConnect = false; resetForNewQuery(); } else // { // .... // String searchable = json.optString("searchable"); } } catch (JSONException e) { // .... // ... } catch (IllegalArgumentException e2) { // .... // ... int aa = 0; } }
From source file:org.eclipse.orion.server.tests.servlets.git.GitConfigTest.java
@Test public void testGetListOfConfigEntries() throws Exception { URI workspaceLocation = createWorkspace(getMethodName()); IPath[] clonePaths = createTestProjects(workspaceLocation); for (IPath clonePath : clonePaths) { // clone a repo String contentLocation = clone(clonePath).getString(ProtocolConstants.KEY_CONTENT_LOCATION); // get project metadata WebRequest request = getGetRequest(contentLocation); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); JSONObject project = new JSONObject(response.getText()); JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT); String gitConfigUri = gitSection.getString(GitConstants.KEY_CONFIG); JSONObject configResponse = listConfigEntries(gitConfigUri); JSONArray configEntries = configResponse.getJSONArray(ProtocolConstants.KEY_CHILDREN); for (int i = 0; i < configEntries.length(); i++) { JSONObject configEntry = configEntries.getJSONObject(i); assertNotNull(configEntry.optString(GitConstants.KEY_CONFIG_ENTRY_KEY, null)); assertNotNull(configEntry.optString(GitConstants.KEY_CONFIG_ENTRY_VALUE, null)); assertConfigUri(configEntry.getString(ProtocolConstants.KEY_LOCATION)); assertCloneUri(configEntry.getString(GitConstants.KEY_CLONE)); assertEquals(ConfigOption.TYPE, configEntry.getString(ProtocolConstants.KEY_TYPE)); }/*from w ww. j a v a 2s.co m*/ } }
From source file:org.eclipse.orion.server.tests.servlets.git.GitConfigTest.java
@Test public void testAddConfigEntry() throws Exception { URI workspaceLocation = createWorkspace(getMethodName()); IPath[] clonePaths = createTestProjects(workspaceLocation); for (IPath clonePath : clonePaths) { // clone a repo String contentLocation = clone(clonePath).getString(ProtocolConstants.KEY_CONTENT_LOCATION); // get project metadata WebRequest request = getGetRequest(contentLocation); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); JSONObject project = new JSONObject(response.getText()); JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT); String gitConfigUri = gitSection.getString(GitConstants.KEY_CONFIG); JSONObject configResponse = listConfigEntries(gitConfigUri); JSONArray configEntries = configResponse.getJSONArray(ProtocolConstants.KEY_CHILDREN); // initial number of config entries int initialConfigEntriesCount = configEntries.length(); // set some dummy value final String ENTRY_KEY = "a.b.c"; final String ENTRY_VALUE = "v"; request = getPostGitConfigRequest(gitConfigUri, ENTRY_KEY, ENTRY_VALUE); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode()); configResponse = new JSONObject(response.getText()); String entryLocation = configResponse.getString(ProtocolConstants.KEY_LOCATION); assertConfigUri(entryLocation);// ww w . j a v a 2 s .c om // get list of config entries again configResponse = listConfigEntries(gitConfigUri); configEntries = configResponse.getJSONArray(ProtocolConstants.KEY_CHILDREN); assertEquals(initialConfigEntriesCount + 1, configEntries.length()); entryLocation = null; for (int i = 0; i < configEntries.length(); i++) { JSONObject configEntry = configEntries.getJSONObject(i); if (ENTRY_KEY.equals(configEntry.getString(GitConstants.KEY_CONFIG_ENTRY_KEY))) { assertConfigOption(configEntry, ENTRY_KEY, ENTRY_VALUE); break; } } // double check org.eclipse.jgit.lib.Config config = getRepositoryForContentLocation(contentLocation).getConfig(); assertEquals(ENTRY_VALUE, config.getString("a", "b", "c")); } }
From source file:fr.pasteque.pos.customers.DataLogicCustomers.java
/** Load customers list from server */ private List<CustomerInfoExt> loadCustomers() throws BasicException { try {//from w w w . j a va2s .c om ServerLoader loader = new ServerLoader(); ServerLoader.Response r = loader.read("CustomersAPI", "getAll"); if (r.getStatus().equals(ServerLoader.Response.STATUS_OK)) { List<CustomerInfoExt> data = new ArrayList<CustomerInfoExt>(); JSONArray a = r.getArrayContent(); for (int i = 0; i < a.length(); i++) { JSONObject o = a.getJSONObject(i); CustomerInfoExt customer = new CustomerInfoExt(o); data.add(customer); } return data; } } catch (Exception e) { throw new BasicException(e); } return null; }
From source file:fr.pasteque.pos.customers.DataLogicCustomers.java
private static void loadDiscountProfiles() throws BasicException { try {/*from w w w .ja v a 2s .co m*/ ServerLoader loader = new ServerLoader(); ServerLoader.Response r = loader.read("DiscountProfilesAPI", "getAll"); if (r.getStatus().equals(ServerLoader.Response.STATUS_OK)) { DataLogicCustomers.discProfileCache = new ArrayList<DiscountProfile>(); JSONArray a = r.getArrayContent(); for (int i = 0; i < a.length(); i++) { JSONObject o = a.getJSONObject(i); DiscountProfile prof = new DiscountProfile(o); DataLogicCustomers.discProfileCache.add(prof); } } } catch (Exception e) { throw new BasicException(e); } }