List of usage examples for org.json JSONObject getInt
public int getInt(String key) throws JSONException
From source file:com.platform.APIClient.java
public long feePerKb() { try {//from www. java 2 s. com String strUtl = BASE_URL + FEE_PER_KB_URL; Request request = new Request.Builder().url(strUtl).get().build(); String body = null; try { Response response = sendRequest(request, false, 0); body = response.body().string(); } catch (IOException e) { e.printStackTrace(); } JSONObject object = null; object = new JSONObject(body); return (long) object.getInt("fee_per_kb"); } catch (JSONException e) { e.printStackTrace(); } return 0; }
From source file:ru.jkff.antro.ReportReader.java
private Stat toStat(JSONObject stat) throws JSONException { double avg = stat.getDouble("avg"); double min = stat.getDouble("min"); double max = stat.getDouble("max"); double first = stat.getDouble("first"); double total = stat.getDouble("total"); int count = stat.getInt("count"); PersistentStack<Call> smin = toStack(stat.getJSONObject("evMin").getJSONArray("stack")); PersistentStack<Call> smax = toStack(stat.getJSONObject("evMax").getJSONArray("stack")); PersistentStack<Call> sfirst = toStack(stat.getJSONObject("evFirst").getJSONArray("stack")); EventWithCallStack evMin = new EventWithCallStack(smin); EventWithCallStack evMax = new EventWithCallStack(smax); EventWithCallStack evFirst = new EventWithCallStack(sfirst); return new Stat(avg, min, max, first, total, count, evMin, evMax, evFirst); }
From source file:ru.jkff.antro.ReportReader.java
private OurLocation toLocation(JSONObject location) throws JSONException { return new OurLocation(location.has("file") ? location.getString("file") : "(unknown file)", location.getInt("line")); }
From source file:com.groupon.odo.proxylib.BackupService.java
/** * 1. Resets profile to get fresh slate//from ww w. ja v a 2 s . c om * 2. Updates active server group to one from json * 3. For each path in json, sets request/response enabled * 4. Adds active overrides to each path * 5. Update arguments and repeat count for each override * * @param profileBackup JSON containing server configuration and overrides to activate * @param profileId Profile to update * @param clientUUID Client UUID to apply update to * @return * @throws Exception Array of errors for things that could not be imported */ public void setProfileFromBackup(JSONObject profileBackup, int profileId, String clientUUID) throws Exception { // Reset the profile before applying changes ClientService clientService = ClientService.getInstance(); clientService.reset(profileId, clientUUID); clientService.updateActive(profileId, clientUUID, true); JSONArray errors = new JSONArray(); // Change to correct server group JSONObject activeServerGroup = profileBackup.getJSONObject(Constants.BACKUP_ACTIVE_SERVER_GROUP); int activeServerId = getServerIdFromName(activeServerGroup.getString(Constants.NAME), profileId); if (activeServerId == -1) { errors.put(formErrorJson("Server Error", "Cannot change to '" + activeServerGroup.getString(Constants.NAME) + "' - Check Server Group Exists")); } else { Client clientToUpdate = ClientService.getInstance().findClient(clientUUID, profileId); ServerRedirectService.getInstance().activateServerGroup(activeServerId, clientToUpdate.getId()); } JSONArray enabledPaths = profileBackup.getJSONArray(Constants.ENABLED_PATHS); PathOverrideService pathOverrideService = PathOverrideService.getInstance(); OverrideService overrideService = OverrideService.getInstance(); for (int i = 0; i < enabledPaths.length(); i++) { JSONObject path = enabledPaths.getJSONObject(i); int pathId = pathOverrideService.getPathId(path.getString(Constants.PATH_NAME), profileId); // Set path to have request/response enabled as necessary try { if (path.getBoolean(Constants.REQUEST_ENABLED)) { pathOverrideService.setRequestEnabled(pathId, true, clientUUID); } if (path.getBoolean(Constants.RESPONSE_ENABLED)) { pathOverrideService.setResponseEnabled(pathId, true, clientUUID); } } catch (Exception e) { errors.put(formErrorJson("Path Error", "Cannot update path: '" + path.getString(Constants.PATH_NAME) + "' - Check Path Exists")); continue; } JSONArray enabledOverrides = path.getJSONArray(Constants.ENABLED_ENDPOINTS); /** * 2 for loops to ensure overrides are added with correct priority * 1st loop is priority currently adding override to * 2nd loop is to find the override with matching priority in profile json */ for (int j = 0; j < enabledOverrides.length(); j++) { for (int k = 0; k < enabledOverrides.length(); k++) { JSONObject override = enabledOverrides.getJSONObject(k); if (override.getInt(Constants.PRIORITY) != j) { continue; } int overrideId; // Name of method that can be used by error message as necessary later String overrideNameForError = ""; // Get the Id of the override try { // If method information is null, then the override is a default override if (override.get(Constants.METHOD_INFORMATION) != JSONObject.NULL) { JSONObject methodInformation = override.getJSONObject(Constants.METHOD_INFORMATION); overrideNameForError = methodInformation.getString(Constants.METHOD_NAME); overrideId = overrideService.getOverrideIdForMethod( methodInformation.getString(Constants.CLASS_NAME), methodInformation.getString(Constants.METHOD_NAME)); } else { overrideNameForError = "Default Override"; overrideId = override.getInt(Constants.OVERRIDE_ID); } // Enable override and set repeat number and arguments overrideService.enableOverride(overrideId, pathId, clientUUID); overrideService.updateRepeatNumber(overrideId, pathId, override.getInt(Constants.PRIORITY), override.getInt(Constants.REPEAT_NUMBER), clientUUID); overrideService.updateArguments(overrideId, pathId, override.getInt(Constants.PRIORITY), override.getString(Constants.ARGUMENTS), clientUUID); } catch (Exception e) { errors.put(formErrorJson("Override Error", "Cannot add/update override: '" + overrideNameForError + "' - Check Override Exists")); continue; } } } } // Throw exception if any errors occured if (errors.length() > 0) { throw new Exception(errors.toString()); } }
From source file:com.karura.framework.plugins.UI.java
@JavascriptInterface // #endif// w w w .ja va2 s . c o m @SupportJavascriptInterface @Description("Load the url into the webview.") @Asynchronous(retVal = "none, will load the specified URL in the webview") @Params({ @Param(name = "callId", description = "The method correlator between javascript and java."), @Param(name = "url", description = "URL to be loaded in the web browser"), @Param(name = "props", description = "Specifies the parameters for customizing the loadUrl experience. Look at " + "WAIT_KEY, OPEN_EXTR_KEY and CLEAR_HISTORY_KEY. If the OPEN_EXTR_KEY is specified then this object can also contain additional " + "parameters which need to be passed to the external viewer in the intent. The other keys can only be integer, boolean or string") }) public void loadUrl(final String callId, String url, JSONObject props) throws JSONException { Log.d(TAG, "loadUrl(" + url + "," + props + ")"); int wait = 0; boolean openExternal = false; boolean clearHistory = false; // If there are properties, then set them on the Activity HashMap<String, Object> params = new HashMap<String, Object>(); if (props != null) { JSONArray keys = props.names(); for (int i = 0; i < keys.length(); i++) { String key = keys.getString(i); if (key.equals(WAIT_KEY)) { wait = props.getInt(key); } else if (key.equalsIgnoreCase(OPEN_EXTR_KEY)) { openExternal = props.getBoolean(key); } else if (key.equalsIgnoreCase(CLEAR_HISTORY_KEY)) { clearHistory = props.getBoolean(key); } else { Object value = props.get(key); if (value == null) { } else if (value.getClass().equals(String.class)) { params.put(key, (String) value); } else if (value.getClass().equals(Boolean.class)) { params.put(key, (Boolean) value); } else if (value.getClass().equals(Integer.class)) { params.put(key, (Integer) value); } } } } // If wait property, then delay loading if (wait > 0) { try { synchronized (this) { this.wait(wait); } } catch (InterruptedException e) { e.printStackTrace(); } } getWebView().showWebPage(url, openExternal, clearHistory, params); }
From source file:com.nokia.example.capturetheflag.network.model.Player.java
public Player(JSONObject jsonObject) throws JSONException { this(jsonObject.getInt(ModelConstants.ID_KEY), jsonObject.getString(ModelConstants.NAME_KEY)); mLatitude = jsonObject.getDouble(ModelConstants.LATITUDE_KEY); mLongitude = jsonObject.getDouble(ModelConstants.LONGITUDE_KEY); mTeam = jsonObject.getString(ModelConstants.TEAM_KEY); mRegId = jsonObject.getString(ModelConstants.REGISTRATION_ID_KEY); }
From source file:com.roger.lineselectionwebview.LSWebView.java
/** * Puts up the selection view.//www . j ava 2s . c om * * @param range * @param text * @param handleBounds * @return */ protected void handleSelection(String range, String text, String handleBounds) { try { JSONObject selectionBoundsObject = new JSONObject(handleBounds); float scale = getDensityIndependentValue(getScale(), mContext); Rect handleRect = new Rect(); handleRect.left = (int) (getDensityDependentValue(selectionBoundsObject.getInt("left"), getContext()) * scale); handleRect.top = (int) (getDensityDependentValue(selectionBoundsObject.getInt("top"), getContext()) * scale); handleRect.right = (int) (getDensityDependentValue(selectionBoundsObject.getInt("right"), getContext()) * scale); handleRect.bottom = (int) (getDensityDependentValue(selectionBoundsObject.getInt("bottom"), getContext()) * scale); mSelectionBounds = handleRect; mSelectedRange = range; mSelectedText = text; if (!isInSelectionMode()) { startSelectionMode(); } drawSelectionHandles(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.roger.lineselectionwebview.LSWebView.java
/** * Calculates the context menu display rect * // w w w. ja v a 2s . c om * @param menuBounds * @return The display Rect */ protected Rect getContextMenuBounds(String menuBounds) { try { JSONObject menuBoundsObject = new JSONObject(menuBounds); float scale = getDensityIndependentValue(getScale(), mContext); Rect displayRect = new Rect(); displayRect.left = (int) (getDensityDependentValue(menuBoundsObject.getInt("left"), getContext()) * scale); displayRect.top = (int) (getDensityDependentValue(menuBoundsObject.getInt("top") - 25, getContext()) * scale); displayRect.right = (int) (getDensityDependentValue(menuBoundsObject.getInt("right"), getContext()) * scale); displayRect.bottom = (int) (getDensityDependentValue(menuBoundsObject.getInt("bottom") + 25, getContext()) * scale); return displayRect; } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:com.roger.lineselectionwebview.LSWebView.java
@Override public void tsjiSelectionClientRects(String rectStr, String selectContext) { // ???bottom/*from ww w. ja va2 s .co m*/ // top+ ??bottom try { float scale = getDensityIndependentValue(getScale(), mContext); JSONArray jsonArray = new JSONArray(rectStr); int length = jsonArray.length(); this.selectContext = selectContext; // TODO ,?new rectList = new ArrayList<Rect>(); for (int i = 0; i < length; i++) { JSONObject jsonObject = jsonArray.getJSONObject(i); Rect handleRect = new Rect(); handleRect.left = (int) (getDensityDependentValue(jsonObject.getInt("left"), getContext()) * scale); handleRect.top = (int) (getDensityDependentValue(jsonObject.getInt("top"), getContext()) * scale); handleRect.right = (int) (getDensityDependentValue(jsonObject.getInt("right"), getContext()) * scale); handleRect.bottom = (int) (getDensityDependentValue(jsonObject.getInt("bottom"), getContext()) * scale); // TODO // handleRect.bottom = 92; rectList.add(handleRect); } } catch (JSONException e) { // e.printStackTrace(); } }
From source file:uk.co.petertribble.jproc.parse.JSONParser.java
private static Set<JLwp> getLwps(JSONArray ja) { Set<JLwp> nlwps = new HashSet<JLwp>(); try {/* ww w. jav a2 s.c o m*/ for (int i = 0; i < ja.length(); i++) { JSONObject jo = ja.getJSONObject(i); nlwps.add(new JLwp(jo.getInt("pid"), jo.getInt("lwpid"))); } } catch (JSONException jse) { // on error, return whatever we have } return nlwps; }