List of usage examples for org.json JSONObject getBoolean
public boolean getBoolean(String key) throws JSONException
From source file:com.hp.mqm.atrf.octane.services.OctaneEntityService.java
private OctaneEntityCollection parseCollection(JSONObject jsonObj) { OctaneEntityCollection coll = new OctaneEntityCollection(); int total = jsonObj.getInt("total_count"); coll.setTotalCount(total);/*from w w w.ja va2 s.c om*/ if (jsonObj.has("exceeds_total_count")) { boolean exceedsTotalCount = jsonObj.getBoolean("exceeds_total_count"); coll.setExceedsTotalCount(exceedsTotalCount); } JSONArray entitiesJArr = jsonObj.getJSONArray("data"); for (int i = 0; i < entitiesJArr.length(); i++) { JSONObject entObj = entitiesJArr.getJSONObject(i); OctaneEntity entity = parseEntity(entObj); coll.getData().add(entity); } return coll; }
From source file:com.norman0406.slimgress.API.Knobs.PortalKnobs.java
public PortalKnobs(JSONObject json) throws JSONException { super(json);/* w ww. jav a 2 s .com*/ JSONObject resonatorLimits = json.getJSONObject("resonatorLimits"); JSONArray bands = resonatorLimits.getJSONArray("bands"); mBands = new ArrayList<Band>(); for (int i = 0; i < bands.length(); i++) { JSONObject band = bands.getJSONObject(i); Band newBand = new Band(); newBand.applicableLevels = getIntArray(band, "applicableLevels"); newBand.remaining = band.getInt("remaining"); mBands.add(newBand); } mCanPlayerRemoveMod = json.getBoolean("canPlayerRemoveMod"); mMaxModsPerPlayer = json.getInt("maxModsPerPlayer"); }
From source file:com.nextgis.firereporter.ScanexNotificationItem.java
public ScanexNotificationItem(Context c, JSONObject object) { Prepare(c);//from w ww .j a va 2 s. c o m try { this.nID = object.getLong("id"); this.dt = new Date(object.getLong("date")); this.X = object.getDouble("X"); this.Y = object.getDouble("Y"); this.nConfidence = object.getInt("confidence"); this.nPower = object.getInt("power"); this.sURL1 = object.getString("URL1"); this.sURL2 = object.getString("URL2"); this.sType = object.getString("type"); this.sPlace = object.getString("place"); this.sMap = object.getString("map"); this.nIconId = object.getInt("iconId"); this.mbWatched = object.getBoolean("watched"); } catch (JSONException e) { SendError(e.getLocalizedMessage()); } }
From source file:org.collectionspace.chain.csp.webui.record.RecordSearchList.java
private JSONObject showBatches(JSONObject data, String type, String key) throws JSONException { JSONObject results = new JSONObject(); JSONArray list = new JSONArray(); JSONArray names = new JSONArray(); JSONArray newFocuses = new JSONArray(); if (data.has(key)) { JSONArray ja = data.getJSONArray(key); for (int j = 0; j < ja.length(); j++) { list.put(ja.getJSONObject(j).getString("csid")); names.put(ja.getJSONObject(j).getString("number")); JSONObject summarylist = ja.getJSONObject(j).getJSONObject("summarylist"); newFocuses.put(summarylist.getBoolean("createsNewFocus")); }/*from ww w . ja v a 2 s.c o m*/ results.put("batchlist", list); results.put("batchnames", names); results.put("batchnewfocuses", newFocuses); } return results; }
From source file:org.rapidandroid.activity.GlobalSettings.java
/** * //from w w w . j a va 2s . c o m */ private void loadSettingsFromGlobals() { // TODO Auto-generated method stub JSONObject globals = ApplicationGlobals.loadSettingsFromFile(this); try { mActiveLoggingSwitch.setChecked(globals.getBoolean(ApplicationGlobals.KEY_ACTIVE_LOGGING)); mActiveSwitch.setChecked(globals.getBoolean(ApplicationGlobals.KEY_ACTIVE_ALL)); mParseCheckbox.setChecked(globals.getBoolean(ApplicationGlobals.KEY_PARSE_REPLY)); mParseReplyText.setText(globals.getString(ApplicationGlobals.KEY_PARSE_REPLY_TEXT)); mNoparseCheckBox.setChecked(globals.getBoolean(ApplicationGlobals.KEY_FAILED_REPLY)); mNoparseReplyText.setText(globals.getString(ApplicationGlobals.KEY_FAILED_REPLY_TEXT)); mParseInProgressCheckbox.setChecked(globals.getBoolean(ApplicationGlobals.KEY_INPROGRESS_REPLY)); mParseInProgressReplyText.setText(globals.getString(ApplicationGlobals.KEY_PARSE_INPROGRESS_TEXT)); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.stormpath.spring.boot.examples.filter.ReCaptchaFilter.java
@Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { if (!(req instanceof HttpServletRequest) || !("POST".equalsIgnoreCase(((HttpServletRequest) req).getMethod()))) { chain.doFilter(req, res);/*from w w w . j a va 2s . c o m*/ return; } PostMethod method = new PostMethod(RECAPTCHA_URL); method.addParameter("secret", RECAPTCHA_SECRET); method.addParameter("response", req.getParameter(RECAPTCHA_RESPONSE_PARAM)); method.addParameter("remoteip", req.getRemoteAddr()); HttpClient client = new HttpClient(); client.executeMethod(method); BufferedReader br = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream())); String readLine; StringBuffer response = new StringBuffer(); while (((readLine = br.readLine()) != null)) { response.append(readLine); } JSONObject jsonObject = new JSONObject(response.toString()); boolean success = jsonObject.getBoolean("success"); if (success) { chain.doFilter(req, res); } else { ((HttpServletResponse) res).sendError(HttpStatus.BAD_REQUEST.value(), "Bad ReCaptcha"); } }
From source file:de.hackerspacebremen.format.JSONFormatter.java
@Override public T reformat(final String object, final Class<T> entityClass) throws FormatException { T result = null;// w w w. ja v a 2 s .co m final Map<String, Field> fieldMap = new HashMap<String, Field>(); if (entityClass.isAnnotationPresent(Entity.class)) { final Field[] fields = entityClass.getDeclaredFields(); for (final Field field : fields) { if (field.isAnnotationPresent(FormatPart.class)) { fieldMap.put(field.getAnnotation(FormatPart.class).key(), field); } } try { final JSONObject json = new JSONObject(object); result = entityClass.newInstance(); for (final String key : fieldMap.keySet()) { if (json.has(key)) { final Field field = fieldMap.get(key); final Method method = entityClass.getMethod(this.getSetter(field.getName()), new Class<?>[] { field.getType() }); final String type = field.getType().toString(); if (type.equals("class com.google.appengine.api.datastore.Key")) { method.invoke(result, KeyFactory.stringToKey(json.getString(key))); } else if (type.equals("class com.google.appengine.api.datastore.Text")) { method.invoke(result, new Text(json.getString(key))); } else if (type.equals("boolean")) { method.invoke(result, json.getBoolean(key)); } else if (type.equals("long")) { method.invoke(result, json.getLong(key)); } else if (type.equals("int")) { method.invoke(result, json.getInt(key)); } else { method.invoke(result, json.get(key)); } } } } catch (JSONException e) { logger.warning("JSONException occured: " + e.getMessage()); throw new FormatException(); } catch (NoSuchMethodException e) { logger.warning("NoSuchMethodException occured: " + e.getMessage()); throw new FormatException(); } catch (SecurityException e) { logger.warning("SecurityException occured: " + e.getMessage()); throw new FormatException(); } catch (IllegalAccessException e) { logger.warning("IllegalAccessException occured: " + e.getMessage()); throw new FormatException(); } catch (IllegalArgumentException e) { logger.warning("IllegalArgumentException occured: " + e.getMessage()); throw new FormatException(); } catch (InvocationTargetException e) { logger.warning("InvocationTargetException occured: " + e.getMessage()); throw new FormatException(); } catch (InstantiationException e) { logger.warning("InstantiationException occured: " + e.getMessage()); throw new FormatException(); } } return result; }
From source file:org.collectionspace.chain.csp.persistence.services.relation.TestRelationsThroughWebapp.java
@Test public void testLoginTest() throws Exception { // initially set up with logged in user ServletTester jetty = tester.setupJetty(); HttpTester out = tester.GETData("/loginstatus", jetty); JSONObject data3 = new JSONObject(out.getContent()); Boolean rel3 = data3.getBoolean("login"); assertTrue(rel3);/*from ww w .j a v a 2s. c om*/ // logout the user out = tester.GETData("/logout", jetty, 303); // should get false out = tester.GETData("/loginstatus", jetty); JSONObject data2 = new JSONObject(out.getContent()); Boolean rel2 = data2.getBoolean("login"); assertFalse(rel2); tester.stopJetty(jetty); }
From source file:com.trk.aboutme.facebook.SharedPreferencesTokenCachingStrategy.java
private void deserializeKey(String key, Bundle bundle) throws JSONException { String jsonString = cache.getString(key, "{}"); JSONObject json = new JSONObject(jsonString); String valueType = json.getString(JSON_VALUE_TYPE); if (valueType.equals(TYPE_BOOLEAN)) { bundle.putBoolean(key, json.getBoolean(JSON_VALUE)); } else if (valueType.equals(TYPE_BOOLEAN_ARRAY)) { JSONArray jsonArray = json.getJSONArray(JSON_VALUE); boolean[] array = new boolean[jsonArray.length()]; for (int i = 0; i < array.length; i++) { array[i] = jsonArray.getBoolean(i); }//w w w . j a v a 2 s. com bundle.putBooleanArray(key, array); } else if (valueType.equals(TYPE_BYTE)) { bundle.putByte(key, (byte) json.getInt(JSON_VALUE)); } else if (valueType.equals(TYPE_BYTE_ARRAY)) { JSONArray jsonArray = json.getJSONArray(JSON_VALUE); byte[] array = new byte[jsonArray.length()]; for (int i = 0; i < array.length; i++) { array[i] = (byte) jsonArray.getInt(i); } bundle.putByteArray(key, array); } else if (valueType.equals(TYPE_SHORT)) { bundle.putShort(key, (short) json.getInt(JSON_VALUE)); } else if (valueType.equals(TYPE_SHORT_ARRAY)) { JSONArray jsonArray = json.getJSONArray(JSON_VALUE); short[] array = new short[jsonArray.length()]; for (int i = 0; i < array.length; i++) { array[i] = (short) jsonArray.getInt(i); } bundle.putShortArray(key, array); } else if (valueType.equals(TYPE_INTEGER)) { bundle.putInt(key, json.getInt(JSON_VALUE)); } else if (valueType.equals(TYPE_INTEGER_ARRAY)) { JSONArray jsonArray = json.getJSONArray(JSON_VALUE); int[] array = new int[jsonArray.length()]; for (int i = 0; i < array.length; i++) { array[i] = jsonArray.getInt(i); } bundle.putIntArray(key, array); } else if (valueType.equals(TYPE_LONG)) { bundle.putLong(key, json.getLong(JSON_VALUE)); } else if (valueType.equals(TYPE_LONG_ARRAY)) { JSONArray jsonArray = json.getJSONArray(JSON_VALUE); long[] array = new long[jsonArray.length()]; for (int i = 0; i < array.length; i++) { array[i] = jsonArray.getLong(i); } bundle.putLongArray(key, array); } else if (valueType.equals(TYPE_FLOAT)) { bundle.putFloat(key, (float) json.getDouble(JSON_VALUE)); } else if (valueType.equals(TYPE_FLOAT_ARRAY)) { JSONArray jsonArray = json.getJSONArray(JSON_VALUE); float[] array = new float[jsonArray.length()]; for (int i = 0; i < array.length; i++) { array[i] = (float) jsonArray.getDouble(i); } bundle.putFloatArray(key, array); } else if (valueType.equals(TYPE_DOUBLE)) { bundle.putDouble(key, json.getDouble(JSON_VALUE)); } else if (valueType.equals(TYPE_DOUBLE_ARRAY)) { JSONArray jsonArray = json.getJSONArray(JSON_VALUE); double[] array = new double[jsonArray.length()]; for (int i = 0; i < array.length; i++) { array[i] = jsonArray.getDouble(i); } bundle.putDoubleArray(key, array); } else if (valueType.equals(TYPE_CHAR)) { String charString = json.getString(JSON_VALUE); if (charString != null && charString.length() == 1) { bundle.putChar(key, charString.charAt(0)); } } else if (valueType.equals(TYPE_CHAR_ARRAY)) { JSONArray jsonArray = json.getJSONArray(JSON_VALUE); char[] array = new char[jsonArray.length()]; for (int i = 0; i < array.length; i++) { String charString = jsonArray.getString(i); if (charString != null && charString.length() == 1) { array[i] = charString.charAt(0); } } bundle.putCharArray(key, array); } else if (valueType.equals(TYPE_STRING)) { bundle.putString(key, json.getString(JSON_VALUE)); } else if (valueType.equals(TYPE_STRING_LIST)) { JSONArray jsonArray = json.getJSONArray(JSON_VALUE); int numStrings = jsonArray.length(); ArrayList<String> stringList = new ArrayList<String>(numStrings); for (int i = 0; i < numStrings; i++) { Object jsonStringValue = jsonArray.get(i); stringList.add(i, jsonStringValue == JSONObject.NULL ? null : (String) jsonStringValue); } bundle.putStringArrayList(key, stringList); } else if (valueType.equals(TYPE_ENUM)) { try { String enumType = json.getString(JSON_VALUE_ENUM_TYPE); @SuppressWarnings({ "unchecked", "rawtypes" }) Class<? extends Enum> enumClass = (Class<? extends Enum>) Class.forName(enumType); @SuppressWarnings("unchecked") Enum<?> enumValue = Enum.valueOf(enumClass, json.getString(JSON_VALUE)); bundle.putSerializable(key, enumValue); } catch (ClassNotFoundException e) { } catch (IllegalArgumentException e) { } } }
From source file:org.akvo.caddisfly.helper.TestConfigHelper.java
private static TestInfo loadTest(JSONObject item) { TestInfo testInfo = null;/*from w w w . ja v a2s . c o m*/ try { //Get the test type TestType type; if (item.has("subtype")) { switch (item.getString("subtype")) { case "liquid-chamber": type = TestType.COLORIMETRIC_LIQUID; break; case "strip": case "striptest": type = TestType.COLORIMETRIC_STRIP; break; case "sensor": type = TestType.SENSOR; break; default: return null; } } else { return null; } //Get the name for this test String name = item.getString("name"); //Load results JSONArray resultsArray = null; if (item.has("results")) { resultsArray = item.getJSONArray("results"); } //Load the dilution percentages String dilutions = "0"; if (item.has("dilutions")) { dilutions = item.getString("dilutions"); if (dilutions.isEmpty()) { dilutions = "0"; } } String[] dilutionsArray = dilutions.split(","); //Load the ranges String ranges = "0"; if (item.has("ranges")) { ranges = item.getString("ranges"); } String[] rangesArray = ranges.split(","); String[] defaultColorsArray = new String[0]; if (item.has("defaultColors")) { String defaultColors = item.getString("defaultColors"); defaultColorsArray = defaultColors.split(","); } // get uuids String uuid = item.getString(SensorConstants.UUID); testInfo = new TestInfo(name, type, rangesArray, defaultColorsArray, dilutionsArray, uuid, resultsArray); testInfo.setHueTrend(item.has("hueTrend") ? item.getInt("hueTrend") : 0); testInfo.setDeviceId(item.has("deviceId") ? item.getString("deviceId") : "Unknown"); testInfo.setResponseFormat(item.has("responseFormat") ? item.getString("responseFormat") : ""); testInfo.setUseGrayScale(item.has("grayScale") && item.getBoolean("grayScale")); testInfo.setMonthsValid(item.has("monthsValid") ? item.getInt("monthsValid") : DEFAULT_MONTHS_VALID); //if calibrate not specified then default to false otherwise use specified value testInfo.setRequiresCalibration(item.has("calibrate") && item.getBoolean("calibrate")); testInfo.setIsDeprecated(item.has("deprecated") && item.getBoolean("deprecated")); } catch (JSONException e) { Timber.e(e); } return testInfo; }