List of usage examples for org.json JSONArray toString
public String toString()
From source file:com.facebook.internal.Utility.java
public static void setAppEventExtendedDeviceInfoParameters(GraphObject params, Context appContext) { JSONArray extraInfoArray = new JSONArray(); extraInfoArray.put(EXTRA_APP_EVENTS_INFO_FORMAT_VERSION); // Application Manifest info: String pkgName = appContext.getPackageName(); int versionCode = -1; String versionName = ""; try {/*ww w . j ava2 s . c o m*/ PackageInfo pi = appContext.getPackageManager().getPackageInfo(pkgName, 0); versionCode = pi.versionCode; versionName = pi.versionName; } catch (PackageManager.NameNotFoundException e) { // Swallow } // Application Manifest info: extraInfoArray.put(pkgName); extraInfoArray.put(versionCode); extraInfoArray.put(versionName); params.setProperty("extinfo", extraInfoArray.toString()); }
From source file:androidGLUESigner.helpers.SettingsHelper.java
/** * Saves the changed document list into sharedprefereces * @param values the new values to be saved * @param editor default shared preferences editor. */// w ww . ja v a2s . co m private void saveNewDocList(ArrayList<String> values, Editor editor) { JSONArray a = new JSONArray(); for (int i = 0; i < values.size(); i++) { a.put(values.get(i)); } if (!values.isEmpty()) { editor.putString("signedDocs", a.toString()); } else { editor.putString("signedDocs", null); } editor.apply(); }
From source file:com.oakesville.mythling.app.AppData.java
private void persistDownloads() throws IOException, JSONException { JSONArray downloadsArr = new JSONArray(); for (Download download : downloads.values()) downloadsArr.put(download.toJson()); writeDownloads(downloadsArr.toString()); }
From source file:ch.icclab.cyclops.resource.impl.AccountingClient.java
/** * This method gets the violations for a given instanceId of a vnf * * @param instanceId//from ww w . j ava 2 s . c om * @return */ public String getVnfViolations(String instanceId) { JSONArray resultArray = null; ClientResource resource = new ClientResource(url + "/sla/vnf-violation/?instanceId=" + instanceId); logger.debug("Call to accounting: " + url + "/sla/vnf-violation/?instanceId=" + instanceId); try { resource.get(MediaType.APPLICATION_JSON); Representation output = resource.getResponseEntity(); String outputText = output.getText().toString(); logger.debug("Response from accounting: " + outputText); resultArray = new JSONArray(outputText); } catch (Exception e) { logger.error("Error getting the response from accounting: " + e.getMessage()); } return resultArray.toString(); }
From source file:ch.icclab.cyclops.resource.impl.AccountingClient.java
/** * This method gets the violations for a given instanceId of a service * * @param instanceId//from w ww.j a v a 2 s . c om * @return */ public String getServiceViolations(String instanceId) { JSONArray resultArray = null; ClientResource resource = new ClientResource(url + "/sla/service-violation/?instanceId=" + instanceId); logger.debug("Call to accounting: " + url + "/sla/service-violation/?instanceId=" + instanceId); try { resource.get(MediaType.APPLICATION_JSON); Representation output = resource.getResponseEntity(); String outputText = output.getText().toString(); logger.debug("Response from accounting: " + outputText); resultArray = new JSONArray(outputText); } catch (Exception e) { logger.error("Error getting the response from accounting: " + e.getMessage()); } return resultArray.toString(); }
From source file:com.pool.rest.CarPoolRestService.java
@GET @Path("/getNotifications") @Produces({ MediaType.APPLICATION_JSON }) public Response getNotifications() { _validateSession();/*from w ww. j ava2s. com*/ HttpSession session = request.getSession(false); User user = (User) session.getAttribute("USER"); NotificationService service = new NotificationService(); List notifications = service.fetchNotifications(user.getUserId()); JSONArray arr = new JSONArray(); if (notifications != null) { for (Object obj : notifications) { Map map = (Map) obj; JSONObject jsonObj = new JSONObject(); for (Object key : map.keySet()) { try { jsonObj.put((String) key, map.get(key)); } catch (JSONException e) { } } arr.put(jsonObj); } } return Response.status(Response.Status.OK).entity(arr.toString()).build(); }
From source file:com.pool.rest.CarPoolRestService.java
@GET @Path("/searchPools") @Produces({ MediaType.APPLICATION_JSON }) public Response searchNearestPools(@QueryParam("srcLat") String srcLat, @QueryParam("srcLng") String srcLng, @QueryParam("destLat") String destLat, @QueryParam("destLng") String destLng, @QueryParam("startTime") String startTime, @QueryParam("anyTime") String anyTime) { _validateSession();// w ww . j a v a 2 s. c o m boolean anyTimeB = false; HttpSession session = request.getSession(false); User usr = (User) session.getAttribute("USER"); Point srcPoint = new Point(Double.parseDouble(srcLat), Double.parseDouble(srcLng)); Point destPoint = new Point(Double.parseDouble(destLat), Double.parseDouble(destLng)); CarPoolService service = new CarPoolService(); System.err.println("Before searching pools ***********************"); if (anyTime != null && anyTime.equalsIgnoreCase("true")) { anyTimeB = true; } Map<Long, GeoPoint> poolIdPointMap = service.findNearestPools(srcPoint, destPoint, Long.parseLong(startTime), usr.getUserId(), anyTimeB); if (poolIdPointMap != null) { List list = service.fetchPoolDetailsById(poolIdPointMap.keySet()); NotificationService nService = new NotificationService(); List poolIdsForSentReqs = nService.getPoolIdsForSentRequests(usr.getUserId(), poolIdPointMap.keySet()); List subsPoolIds = nService.getSubscribedPoolIds(usr.getUserId()); JSONArray array = new JSONArray(); try { for (int i = 0; i < list.size(); i++) { Object result[] = (Object[]) list.get(i); Carpool pool = (Carpool) result[0]; if (!subsPoolIds.contains(pool.getCarPoolId())) { User user = (User) result[1]; user.setCarpools(null); user.setVehicles(null); pool.setCalendarDays(null); // pool.setGeoPoints(null); List<GeoPoint> allPoints = service.fetchGeoPointsByPoolId(pool.getCarPoolId()); GeoPoint nearPoint = PoolUtils.findNearestPoint(destPoint.getLattitude().toString(), destPoint.getLongitude().toString(), allPoints); GeoPoint startPoint = allPoints.get(0); GeoPoint dropPoint = nearPoint; pool.setGeoPoints(null); JSONObject map = new JSONObject(); JSONObject poolJson = new JSONObject(pool); GeoPoint pickupPoint = poolIdPointMap.get(pool.getCarPoolId()); poolJson.put("pickupTime", pickupPoint.getApproxTimeToReach()); //poolJson.put("pickupTime", startTime); poolJson.put("pickupLattitude", pickupPoint.getLatitude()); poolJson.put("pickupLongitude", pickupPoint.getLongitude()); poolJson.put("dropLattitude", dropPoint.getLatitude()); poolJson.put("dropLongitude", dropPoint.getLongitude()); poolJson.put("pickupDistance", ((float) (pickupPoint .getDistanceToReach() - startPoint.getDistanceToReach())) / 1000.00); poolJson.put("tripDistance", ((float) (dropPoint.getDistanceToReach() - pickupPoint.getDistanceToReach())) / 1000.00); poolJson.put("tripCost", ((float) (dropPoint.getDistanceToReach() - pickupPoint.getDistanceToReach()) * pool.getBucksPerKm()) / 1000.0); if (poolIdsForSentReqs.contains(pool.getCarPoolId())) { poolJson.put("requestReceived", true); } map.put("owner", new JSONObject(user)); map.put("carpool", poolJson); array.put(map); } } } catch (JSONException e) { e.printStackTrace(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } return Response.status(Response.Status.OK).entity(array.toString()).build(); } return Response.status(Response.Status.NOT_FOUND).build(); }
From source file:com.pool.rest.CarPoolRestService.java
@POST @Path("/myPools") @Produces({ MediaType.APPLICATION_JSON }) public Response getMyPools() { _validateSession();/*w w w.java 2s .c o m*/ HttpSession session = request.getSession(false); User usr = (User) session.getAttribute(PoolConstants.USER_SESSION_ATTR); CarPoolService service = new CarPoolService(); List<Carpool> carPools = service.findPoolsByUserId(usr.getUserId()); JSONArray array = new JSONArray(); List<Long> carPoolIds = new ArrayList<Long>(); for (Carpool pool : carPools) { carPoolIds.add(pool.getCarPoolId()); } Map<Long, PoolSubscription> subs = null; if (carPoolIds != null && carPoolIds.size() > 0) { subs = service.fetchTravellerSubscriptions(carPoolIds, usr.getUserId()); } for (Carpool pool : carPools) { pool.setCalendarDays(null); JSONObject poolJson = new JSONObject(pool); array.put(poolJson); try { if (pool.getOwnerId().equals(usr.getUserId())) { poolJson.put("isOwner", true); poolJson.put("pickupTime", pool.getStartTime()); poolJson.put("cost", service.getPerTripCollection(pool.getCarPoolId())); } else { PoolSubscription sub = subs.get(pool.getCarPoolId()); poolJson.put("isOwner", false); poolJson.put("pickupTime", sub.getPickupTime()); poolJson.put("cost", sub.getTripCost()); } } catch (JSONException e) { } } return Response.status(Response.Status.OK).entity(array.toString()).build(); }
From source file:com.google.enterprise.connector.ldap.LdapConnectorConfigTest.java
/** * Generates a String representation of schema attributes as the UI would * generate when user clicks on one or more checkboxes to select schema * attributes./*from www . j a v a2s . c o m*/ * @return String of the regex [<delemiter-value>attribute1]* */ private String getSchemaValue(String... attributes) { JSONArray arr = new JSONArray(); for (String attribute : attributes) { arr.put(attribute); } return arr.toString(); }
From source file:com.google.enterprise.connector.ldap.LdapConnectorConfigTest.java
public void testBigSchema() { Builder<String, String> builder = ImmutableMap.<String, String>builder(); builder.put("authtype", "ANONYMOUS").put("hostname", "ldap.realistic-looking-domain.com") .put("method", "STANDARD").put("basedn", "ou=people,dc=example,dc=com").put("filter", "ou=people"); JSONArray arr = new JSONArray(); for (int i = 0; i < 200; i++) { arr.put("attribute" + i); }/* ww w . j a v a2 s . co m*/ builder.put(ConfigName.SCHEMAVALUE.toString(), arr.toString()); ImmutableMap<String, String> configMap = builder.build(); LdapConnectorConfig ldapConnectorConfig = new LdapConnectorConfig(configMap); Set<String> schema = ldapConnectorConfig.getSchema(); assertEquals(LdapHandler.DN_ATTRIBUTE, ldapConnectorConfig.getSchemaKey()); assertTrue(schema.contains(LdapHandler.DN_ATTRIBUTE)); //200 from the for loop and 1 for the DN assertEquals(201, schema.size()); for (int i = 0; i < 200; i++) { assertTrue(schema.contains("attribute" + i)); } }