List of usage examples for org.json JSONArray JSONArray
public JSONArray(Object array) throws JSONException
From source file:com.snappy.couchdb.ConnectionHandler.java
/** * Convert a string response to JSON array * /*from w w w.j a va2s. c o m*/ * @param result * @return * @throws JSONException */ private static JSONArray jArrayFromString(String result) throws JSONException { Logger.debug("response to json", result); return new JSONArray(result); }
From source file:net.bither.api.GetKlineApi.java
@Override public void setResult(String response) throws Exception { JSONArray jsonArray = new JSONArray(response); this.result = ChartsUtil.formatJsonArray(this.marketType, this.klineTimeType, jsonArray); }
From source file:com.sudhirkhanger.andpress.rest.WordPressAsyncTask.java
private ArrayList<Post> jsonConvertor(String postJsonStr) { ArrayList<Post> postArrayList = new ArrayList<>(); try {/* w ww . j a v a 2 s .c om*/ JSONArray baseJsonArray = new JSONArray(postJsonStr); int numberOfItems = baseJsonArray.length(); for (int i = 0; i < numberOfItems; i++) { JSONObject item = baseJsonArray.getJSONObject(i); int id = item.optInt(ID); JSONObject titleObject = item.getJSONObject(TITLE); String title = titleObject.optString(RENDERED); JSONObject contentObject = item.getJSONObject(CONTENT); String content = contentObject.optString(RENDERED); String featured_media = item.optString(FEATURED_MEDIA); Post post = new Post(id, title, featured_media, content); postArrayList.add(post); } } catch (JSONException e) { Log.e(LOG_TAG, "Problem parsing the WordPress JSON results", e); } return postArrayList; }
From source file:com.ibm.iot.auto.bluemix.samples.ui.InputData.java
public List<CarProbe> getCarProbes() throws IOException, JSONException { List<CarProbe> carProbes = new ArrayList<CarProbe>(); FileReader fileReader = null; try {// w w w .j a va 2s . c o m fileReader = new FileReader(inputFile); JSONTokener jsonTokener = new JSONTokener(fileReader); JSONArray cars = new JSONArray(jsonTokener); for (int i = 0; i < cars.length(); i++) { JSONObject car = cars.getJSONObject(i); CarProbe carProbe = new CarProbe(car.getString("trip_id"), car.getString("timestamp"), car.getDouble("heading"), car.getDouble("speed"), car.getDouble("longitude"), car.getDouble("latitude")); carProbes.add(carProbe); } } finally { if (fileReader != null) { fileReader.close(); } } Collections.sort(carProbes); return carProbes; }
From source file:nl.hnogames.domoticzapi.Parsers.TemperaturesParser.java
@Override public void parseResult(String result) { try {/*from w w w.j av a 2 s .co m*/ JSONArray jsonArray = new JSONArray(result); ArrayList<TemperatureInfo> mTemperatures = new ArrayList<>(); if (jsonArray.length() > 0) { for (int i = 0; i < jsonArray.length(); i++) { JSONObject row = jsonArray.getJSONObject(i); mTemperatures.add(new TemperatureInfo(row)); } } temperatureReceiver.onReceiveTemperatures(mTemperatures); } catch (JSONException e) { Log.e(TAG, "TemperatureParser JSON exception"); e.printStackTrace(); temperatureReceiver.onError(e); } }
From source file:br.com.indigo.android.facebook.SocialFacebook.java
/** Shingle **/ public void shingleConfiguration(final String url, final int area, final ShingleListener listener) { new Thread() { @Override// www . j a v a 2s .com public void run() { try { Bundle params = new Bundle(); params.putString("area_id", String.valueOf(area)); String response = Util.openUrl(url + "facebook/getFacebook", "GET", params); try { JSONArray result = new JSONArray(response); String profileId = result.getJSONObject(0).getString("account_number"); Log.d(TAG, "Shingle profileId = " + profileId); listener.onComplete(profileId, false); } catch (JSONException e) { Log.d(TAG, "Could not parse server response", e); listener.onFail(new RuntimeException("Could not parse server response", e)); } } catch (MalformedURLException e) { Log.d(TAG, "Error retrieving App Acess Token", e); listener.onFail(e); } catch (IOException e) { Log.d(TAG, "Error retrieving App Acess Token", e); listener.onFail(e); } } }.start(); }
From source file:com.ihgoo.allinone.volley.toolbox.JsonArrayRequest.java
@Override protected Response<JSONArray> parseNetworkResponse(NetworkResponse response) { try {/*from www.ja v a2 s . c o m*/ String jsonString = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); return Response.success(new JSONArray(jsonString), HttpHeaderParser.parseCacheHeaders(response)); } catch (UnsupportedEncodingException e) { return Response.error(new ParseError(e)); } catch (JSONException je) { return Response.error(new ParseError(je)); } }
From source file:re.notifica.cordova.NotificarePlugin.java
/** * Fetch the device tags//w ww. j av a2 s. c om * @param args * @param callbackContext */ protected void fetchDeviceTags(JSONArray args, final CallbackContext callbackContext) { Log.d(TAG, "FETCHTAGS"); Notificare.shared().fetchDeviceTags(new NotificareCallback<List<String>>() { @Override public void onSuccess(List<String> tags) { if (callbackContext == null) { return; } callbackContext.success(new JSONArray(tags)); } @Override public void onError(NotificareError error) { if (callbackContext == null) { return; } callbackContext.error(error.getLocalizedMessage()); } }); }
From source file:org.wso2.carbon.connector.integration.test.pivotaltracker.PivotaltrackerConnectorIntegrationTest.java
/** * Positive test case for listProjects method with mandatory parameters. * //from w ww .j a va 2s . c o m * @throws JSONException * @throws IOException */ @Test(groups = { "wso2.esb" }, dependsOnMethods = { "testCreateProjectWithMandatoryParameters", "testCreateProjectWithOptionalParameters" }, description = "pivotaltracker {listProjects} integration test with mandatory parameters.") public void testListProjectsWithMandatoryParameters() throws IOException, JSONException { esbRequestHeadersMap.put("Action", "urn:listProjects"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_listProjects_mandatory.json"); JSONArray esbOutputArray = new JSONArray(esbRestResponse.getBody().getString("output")); final String apiEndpoint = apiEndpointUrl + "/projects"; RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndpoint, "GET", apiRequestHeadersMap); JSONArray apiOutputArray = new JSONArray(apiRestResponse.getBody().getString("output")); Assert.assertEquals(esbOutputArray.length(), apiOutputArray.length()); Assert.assertEquals(esbOutputArray.getJSONObject(0).getString("id"), apiOutputArray.getJSONObject(0).getString("id")); Assert.assertEquals(esbOutputArray.getJSONObject(0).getString("name"), apiOutputArray.getJSONObject(0).getString("name")); Assert.assertEquals(esbOutputArray.getJSONObject(0).getString("account_id"), apiOutputArray.getJSONObject(0).getString("account_id")); Assert.assertEquals(esbOutputArray.getJSONObject(0).getString("kind"), apiOutputArray.getJSONObject(0).getString("kind")); Assert.assertEquals(esbOutputArray.getJSONObject(0).getString("week_start_day"), apiOutputArray.getJSONObject(0).getString("week_start_day")); }
From source file:org.wso2.carbon.connector.integration.test.pivotaltracker.PivotaltrackerConnectorIntegrationTest.java
/** * Positive test case for listProjects method with optional parameters. * /*from w ww. j a v a 2 s . co m*/ * @throws JSONException * @throws IOException */ @Test(groups = { "wso2.esb" }, dependsOnMethods = { "testCreateProjectWithMandatoryParameters", "testCreateProjectWithOptionalParameters" }, description = "pivotaltracker {listProjects} integration test with mandatory parameters.") public void testListProjectsWithOptionalParameters() throws IOException, JSONException { esbRequestHeadersMap.put("Action", "urn:listProjects"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_listProjects_optional.json"); JSONArray esbOutputArray = new JSONArray(esbRestResponse.getBody().getString("output")); final String apiEndpoint = apiEndpointUrl + "/projects"; RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndpoint, "GET", apiRequestHeadersMap); JSONArray apiOutputArray = new JSONArray(apiRestResponse.getBody().getString("output")); Assert.assertNotEquals(esbOutputArray.length(), apiOutputArray.length()); Assert.assertEquals(esbRestResponse.getHttpStatusCode(), 200); Assert.assertEquals(apiRestResponse.getHttpStatusCode(), 200); }