List of usage examples for org.json JSONObject getInt
public int getInt(String key) throws JSONException
From source file:org.ryancutter.barcajolt.BarcaJolt.java
/** * read "total_rows" from JSONObject returned by view request * //from w w w. j a va2s . c o m * @param jObject JSONObject returned by view request * * @return int Value of "total_rows". Returns -1 if not found. */ public static int getTotalRows(JSONObject jObject) { int totalRows = -1; try { totalRows = jObject.getInt("total_rows"); } catch (JSONException e) { Log.e(TAG, "JSONException while looking for 'total_rows'", e); } return totalRows; }
From source file:org.ryancutter.barcajolt.BarcaJolt.java
/** * read "offset" from JSONObject returned by view request * /*from w w w .jav a 2 s . c om*/ * @param jObject JSONObject returned by view request * * @return int Value of "offset". Returns -1 if not found. */ public static int getOffset(JSONObject jObject) { int offset = -1; try { offset = jObject.getInt("offset"); } catch (JSONException e) { Log.e(TAG, "JSONException while looking for 'offset'", e); } return offset; }
From source file:net.jmhertlein.mcanalytics.api.request.UniqueLoginsPerDayRequest.java
@Override public Map<LocalDate, Integer> processResponse(JSONObject response) { JSONObject counts = response.getJSONObject("logins"); LinkedHashMap<LocalDate, Integer> ret = new LinkedHashMap<>(); for (String s : counts.keySet()) { ret.put(LocalDate.parse(s), counts.getInt(s)); }//from w w w .ja v a2 s. c o m return ret; }
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; }// ww w . j a va 2s . c o m } if (unreadCount == -1) { System.err.println("Unkown id: " + id); } return unreadCount; }
From source file:org.cvrgrid.waveform.backing.GlobusUploadBacking.java
/** * Private API that polls all the endpoints for a user. *//*from ww w.ja v a2 s.c o m*/ private Status getEndpoints(JSONTransferAPIClient client, String query, String endpointType) { try { JSONTransferAPIClient.Result r = client.getResult(query); Map<String, GlobusEndpointList> globusEndpointLists = this.getGlobusEndpointLists(); GlobusEndpointList globusEndpointList = globusEndpointLists.get(endpointType); logger.info("Endpoint Listing " + query + " for " + client.getUsername() + ": "); Iterator<?> keys = r.document.keys(); while (keys.hasNext()) { String next = (String) keys.next(); if (next.equalsIgnoreCase("data_type")) { globusEndpointList.setDataType(r.document.getString(next)); } else if (next.equalsIgnoreCase("length")) { globusEndpointList.setLength(new Integer(r.document.getString(next))); } else if (next.equalsIgnoreCase("limit")) { globusEndpointList.setLimit(r.document.getString(next)); } else if (next.equalsIgnoreCase("offset")) { globusEndpointList.setOffset(r.document.getString(next)); } else if (next.equalsIgnoreCase("total")) { globusEndpointList.setTotal(r.document.getString(next)); } else if (next.equalsIgnoreCase("data")) { JSONArray data = r.document.getJSONArray(next); int size = data.length(); ArrayList<GlobusEndpoint> globusEndpoints = new ArrayList<GlobusEndpoint>(); for (int j = 0; j < size; j++) { GlobusEndpoint globusEndpoint = new GlobusEndpoint(); JSONObject globusEndpointInfo = data.getJSONObject(j); Iterator<?> keys2 = globusEndpointInfo.keys(); while (keys2.hasNext()) { String next2 = (String) keys2.next(); if (next2.equalsIgnoreCase("data_type")) { globusEndpoint.setDataType(globusEndpointInfo.getString(next2)); } else if (next2.equalsIgnoreCase("username")) { globusEndpoint.setUserName(globusEndpointInfo.getString(next2)); } else if (next2.equalsIgnoreCase("globus_connect_setup_key")) { globusEndpoint.setGlobusConnectSetupKey(globusEndpointInfo.getString(next2)); } else if (next2.equalsIgnoreCase("name")) { globusEndpoint.setName(globusEndpointInfo.getString(next2)); } else if (next2.equalsIgnoreCase("activated")) { globusEndpoint.setActivated(globusEndpointInfo.getBoolean(next2)); } else if (next2.equalsIgnoreCase("is_globus_connect")) { globusEndpoint.setIsGlobusConnect(globusEndpointInfo.getBoolean(next2)); } else if (next2.equalsIgnoreCase("ls_link")) { JSONObject linkInfo = globusEndpointInfo.getJSONObject(next2); GlobusLink lsLink = new GlobusLink(); Iterator<?> keys3 = linkInfo.keys(); while (keys3.hasNext()) { String next3 = (String) keys3.next(); if (next3.equalsIgnoreCase("data_type")) { lsLink.setDataType(linkInfo.getString(next3)); } else if (next3.equalsIgnoreCase("href")) { lsLink.setHref(linkInfo.getString(next3)); } else if (next3.equalsIgnoreCase("resource")) { lsLink.setResource(linkInfo.getString(next3)); } else if (next3.equalsIgnoreCase("relationship")) { lsLink.setRelationship(linkInfo.getString(next3)); } else if (next3.equalsIgnoreCase("title")) { lsLink.setTitle(linkInfo.getString(next3)); } } globusEndpoint.setLsLink(lsLink); } else if (next2.equalsIgnoreCase("canonical_name")) { globusEndpoint.setCanonicalName(globusEndpointInfo.getString(next2)); } else if (next2.equalsIgnoreCase("myproxy_server")) { globusEndpoint.setMyProxyServer(globusEndpointInfo.getString(next2)); } else if (next2.equalsIgnoreCase("expire_time")) { //globusEndpoint.setExpireTime(new Date(globusEndpointInfo.getString(next2))); } else if (next2.equalsIgnoreCase("public")) { globusEndpoint.setGlobusPublic(globusEndpointInfo.getBoolean(next2)); } else if (next2.equalsIgnoreCase("description")) { globusEndpoint.setDescription(globusEndpointInfo.getString(next2)); } else if (next2.equalsIgnoreCase("data")) { JSONArray serverData = globusEndpointInfo.getJSONArray(next2); int serverDataSize = serverData.length(); ArrayList<GlobusServer> globusServers = new ArrayList<GlobusServer>(); for (int k = 0; k < serverDataSize; k++) { GlobusServer globusServer = new GlobusServer(); JSONObject globusServerInfo = serverData.getJSONObject(k); Iterator<?> keys4 = globusServerInfo.keys(); while (keys4.hasNext()) { String next4 = (String) keys4.next(); if (next4.equalsIgnoreCase("data_type")) { globusServer.setDataType(globusServerInfo.getString(next4)); } else if (next4.equalsIgnoreCase("id")) { globusServer.setId(globusServerInfo.getInt(next4)); } else if (next4.equalsIgnoreCase("hostname")) { globusServer.setHostname(globusServerInfo.getString(next4)); } else if (next4.equalsIgnoreCase("uri")) { globusServer.setUri(globusServerInfo.getString(next4)); } else if (next4.equalsIgnoreCase("scheme")) { globusServer.setScheme(globusServerInfo.getString(next4)); } else if (next4.equalsIgnoreCase("port")) { if (globusServerInfo.get("port").toString().equalsIgnoreCase("null")) { globusServer.setPort(0); } else { globusServer.setPort(globusServerInfo.getInt(next4)); } } else if (next4.equalsIgnoreCase("subject")) { globusServer.setSubject(globusServerInfo.getString(next4)); } else if (next4.equalsIgnoreCase("is_connected")) { globusServer.setIsConnected(globusServerInfo.getBoolean(next4)); } } globusServers.add(globusServer); } globusEndpoint.setGlobusServers(globusServers); } } globusEndpoints.add(globusEndpoint); } globusEndpointList.setGlobusEndpoints(globusEndpoints); } } globusEndpointLists.put(endpointType, globusEndpointList); this.setGlobusEndpointLists(globusEndpointLists); return Status.OK; } catch (Exception e) { logger.error("Got an exception..\n"); logger.error(e.getMessage()); logger.error(e.getStackTrace().toString()); e.printStackTrace(); return Status.FAIL; } }
From source file:com.synox.android.providers.UsersAndGroupsSearchProvider.java
private Cursor searchForUsersOrGroups(Uri uri) { MatrixCursor response = null;/*from w w w . j a v a 2 s .c o m*/ String userQuery = uri.getLastPathSegment().toLowerCase(); /// need to trust on the AccountUtils to get the current account since the query in the client side is not /// directly started by our code, but from SearchView implementation Account account = AccountUtils.getCurrentOwnCloudAccount(getContext()); /// request to the OC server about users and groups matching userQuery GetRemoteShareesOperation searchRequest = new GetRemoteShareesOperation(userQuery, REQUESTED_PAGE, RESULTS_PER_PAGE); RemoteOperationResult result = searchRequest.execute(account, getContext()); List<JSONObject> names = new ArrayList<JSONObject>(); if (result.isSuccess()) { for (Object o : result.getData()) { // Get JSonObjects from response names.add((JSONObject) o); } } else { showErrorMessage(result); } /// convert the responses from the OC server to the expected format if (names.size() > 0) { response = new MatrixCursor(COLUMNS); Iterator<JSONObject> namesIt = names.iterator(); int count = 0; JSONObject item; String displayName; Uri dataUri; Uri userBaseUri = new Uri.Builder().scheme("content").authority(DATA_USER).build(); Uri groupBaseUri = new Uri.Builder().scheme("content").authority(DATA_GROUP).build(); try { while (namesIt.hasNext()) { item = namesIt.next(); String userName = item.getString(GetRemoteShareesOperation.PROPERTY_LABEL); JSONObject value = item.getJSONObject(GetRemoteShareesOperation.NODE_VALUE); byte type = (byte) value.getInt(GetRemoteShareesOperation.PROPERTY_SHARE_TYPE); String shareWith = value.getString(GetRemoteShareesOperation.PROPERTY_SHARE_WITH); if (GetRemoteShareesOperation.GROUP_TYPE.equals(type)) { displayName = getContext().getString(R.string.share_group_clarification, userName); dataUri = Uri.withAppendedPath(groupBaseUri, shareWith); } else { displayName = userName; dataUri = Uri.withAppendedPath(userBaseUri, shareWith); } response.newRow().add(count++) // BaseColumns._ID .add(displayName) // SearchManager.SUGGEST_COLUMN_TEXT_1 .add(dataUri); } } catch (JSONException e) { Log_OC.e(TAG, "Exception while parsing data of users/groups", e); } } return response; }
From source file:com.bmwcarit.barefoot.roadmap.Loader.java
/** * Reads road type configuration from JSON representation. * * @param jsonconfig JSON representation of the road type configuration. * @return Mapping of road class identifiers to priority factor and default maximum speed. * @throws JSONException thrown on JSON extraction or parsing error. *//* w w w .ja v a2 s. c o m*/ public static Map<Short, Tuple<Double, Integer>> roadtypes(JSONObject jsonconfig) throws JSONException { Map<Short, Tuple<Double, Integer>> config = new HashMap<>(); JSONArray jsontags = jsonconfig.getJSONArray("tags"); for (int i = 0; i < jsontags.length(); ++i) { JSONObject jsontag = jsontags.getJSONObject(i); JSONArray jsonvalues = jsontag.getJSONArray("values"); for (int j = 0; j < jsonvalues.length(); ++j) { JSONObject jsonvalue = jsonvalues.getJSONObject(j); config.put((short) jsonvalue.getInt("id"), new Tuple<>(jsonvalue.getDouble("priority"), jsonvalue.getInt("maxspeed"))); } } return config; }
From source file:com.cssweb.android.view.FinanceMini.java
public void drawHKPrice(Canvas canvas) { Paint paint = this.mPaint; paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setAntiAlias(true);/*from w ww. j a v a 2s. c om*/ if (quoteData != null) { try { JSONArray jArr = quoteData.getJSONArray("data"); JSONObject jo = jArr.getJSONObject(0); paint.setTextAlign(Paint.Align.LEFT); paint.setTextSize(mTextSize); paint.setColor(GlobalColor.colorLabelName); canvas.translate(0, DY); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); canvas.drawText("?", x, y, paint); paint.setTextAlign(Paint.Align.RIGHT); paint.setColor(GlobalColor.colorStockName); canvas.translate(width / 2, -DY * 4); canvas.drawText(Utils.getAmountFormat(jo.getInt("cjsl"), false), x - tips, y, paint); canvas.translate(0, DY); // if(jo.getDouble("wb")<0) // paint.setColor(GlobalColor.colorPriceDown); // else if(jo.getDouble("wb")>0) // paint.setColor(GlobalColor.colorpriceUp); // else // paint.setColor(GlobalColor.colorPriceEqual); // canvas.drawText(Utils.dataFormation(jo.getDouble("wb")*100, 1)+"%", x-tips, y, paint); canvas.drawText(Utils.getAmountFormat(jo.getInt("cjje"), false), x - tips, y, paint); paint.setColor(GlobalColor.colorpriceUp); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("wp"), false), x - tips, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getInt("msgs"), true), x - tips, y, paint); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.translate(0, -DY * 3); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); // canvas.drawText("", x, y, paint); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); // canvas.translate(0, DY); // canvas.drawText("?", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); paint.setTextAlign(Paint.Align.RIGHT); canvas.translate(width / 2, -DY * 3); paint.setColor(GlobalColor.colorStockName); canvas.drawText(Utils.dataFormation(jo.getDouble("lb"), 1, jo.getInt("tp")), x - tips, y, paint); canvas.translate(0, DY); // if(jo.getDouble("wc")<0) { // paint.setColor(GlobalColor.colorPriceDown); // canvas.drawText("-" + Utils.getAmountFormat(Math.abs(jo.getDouble("wc")), true), x-tips, y, paint); // } // else if(jo.getDouble("wc")>0) { // paint.setColor(GlobalColor.colorpriceUp); // canvas.drawText(Utils.getAmountFormat(jo.getDouble("wc"), true), x-tips, y, paint); // } // else { // paint.setColor(GlobalColor.colorPriceEqual); // canvas.drawText(Utils.getAmountFormat(jo.getDouble("wc"), true), x-tips, y, paint); // } paint.setColor(GlobalColor.colorPriceDown); canvas.drawText("", x - tips, y, paint); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("np"), false), x - tips, y, paint); // paint.setColor(GlobalColor.colorStockName); // canvas.translate(0, DY); // canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjje"), true), x-tips, y, paint); } catch (JSONException e) { Log.e(TAG, e.toString()); } } }
From source file:com.cssweb.android.view.FinanceMini.java
public void drawPrice(Canvas canvas) { //canvas.restore(); Paint paint = this.mPaint; paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setAntiAlias(true);//from w w w .j a va 2s. c om if (quoteData != null) { try { JSONArray jArr = quoteData.getJSONArray("data"); JSONObject jo = jArr.getJSONObject(0); paint.setTextAlign(Paint.Align.LEFT); paint.setTextSize(mTextSize); paint.setColor(GlobalColor.colorLabelName); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); int syjd = jo.getInt("syjd"); switch (syjd) { case 1: canvas.drawText("()", x, y, paint); break; case 2: canvas.drawText("()", x, y, paint); break; case 3: canvas.drawText("()", x, y, paint); break; case 4: canvas.drawText("()", x, y, paint); break; default: canvas.drawText("", x, y, paint); break; } if (jo.getDouble("wb") < 0) paint.setColor(GlobalColor.colorPriceDown); else if (jo.getDouble("wb") > 0) paint.setColor(GlobalColor.colorpriceUp); else paint.setColor(GlobalColor.colorPriceEqual); paint.setTextAlign(Paint.Align.RIGHT); canvas.translate(width / 2, -DY * 5); if (jo.getInt("tp") == 1) canvas.drawText("", x - tips, y, paint); else canvas.drawText(Utils.dataFormation(jo.getDouble("wb") * 100, 1) + "%", x - tips, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getInt("cjsl"), false), x - tips, y, paint); paint.setColor(GlobalColor.colorpriceUp); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("wp"), false), x - tips, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("hs") * 100, 1) + "%", x - tips, y, paint); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("jz"), 1), x - tips, y, paint); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("mgsy"), 2), x - tips, y, paint); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.translate(0, -DY * 5); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); if (NameRule.isBond(type)) canvas.drawText("", x, y, paint); else canvas.drawText("PE()", x, y, paint); paint.setTextAlign(Paint.Align.RIGHT); canvas.translate(width / 2, -DY * 5); if (jo.getDouble("wc") < 0) { paint.setColor(GlobalColor.colorPriceDown); canvas.drawText("-" + Utils.getAmountFormat(Math.abs(jo.getDouble("wc")), true), x - tips, y, paint); } else if (jo.getDouble("wc") > 0) { paint.setColor(GlobalColor.colorpriceUp); canvas.drawText(Utils.getAmountFormat(jo.getDouble("wc"), true), x - tips, y, paint); } else { paint.setColor(GlobalColor.colorPriceEqual); canvas.drawText(Utils.getAmountFormat(jo.getDouble("wc"), false), x - tips, y, paint); } paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("lb"), 1, jo.getInt("tp")), x - tips, y, paint); paint.setColor(GlobalColor.colorPriceDown); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("np"), false), x - tips, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("gb"), true), x - tips, y, paint); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("ltsl") * 100, true), x - tips, y, paint); canvas.translate(0, DY); if (NameRule.isBond(type)) { canvas.drawText(Utils.dataFormation(jo.getDouble("fullprice"), 1), x - tips, y, paint); } else { canvas.drawText(Utils.dataFormation(jo.getDouble("sy"), 1), x - tips, y, paint); } } catch (JSONException e) { Log.e(TAG, e.toString()); } } }
From source file:com.cssweb.android.view.FinanceMini.java
public void drawHKIndex(Canvas canvas) { Paint paint = this.mPaint; paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setAntiAlias(true);//from w ww . j a v a2s . c om if (quoteData != null) { try { JSONArray jArr = quoteData.getJSONArray("data"); JSONObject jo = jArr.getJSONObject(0); paint.setTextAlign(Paint.Align.LEFT); paint.setTextSize(mTextSize); paint.setColor(GlobalColor.colorLabelName); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); paint.setTextAlign(Paint.Align.RIGHT); canvas.translate(width, -DY * 3); paint.setColor(GlobalColor.colorpriceUp); canvas.translate(0, DY); canvas.drawText(String.valueOf(jo.getInt("zj")), x - tips, y, paint); paint.setColor(GlobalColor.colorPriceEqual); canvas.translate(0, DY); canvas.drawText(String.valueOf(jo.getInt("pj")), x - tips, y, paint); paint.setColor(GlobalColor.colorPriceDown); canvas.translate(0, DY); canvas.drawText(String.valueOf(jo.getInt("dj")), x - tips, y, paint); } catch (JSONException e) { Log.e(TAG, e.toString()); } } }