/** * Get extra double value. * @param key The key of the stored value. * @return The stored value. * @throws JSONException If the mapping doesn't exist or is not the required type. */ public double getExtraDouble(String key) throws JSONException { return mExtraData.getDouble(key); }
/** * Get extra double value. * @param key The key of the stored value. * @return The stored value. * @throws JSONException If the mapping doesn't exist or is not the required type. */ public double getExtraDouble(String key) throws JSONException { return mExtraData.getDouble(key); }
/** * Get an optional double associated with a key, or the defaultValue if * there is no such key or if its value is not a number. If the value is a * string, an attempt will be made to evaluate it as a number. * * @param key * A key string. * @param defaultValue * The default. * @return An object which is the value. */ public double optDouble(String key, double defaultValue) { try { return this.getDouble(key); } catch (Exception e) { return defaultValue; } }
public static Double getDoubleValue(String json, String key) { try { JSONObject object = new JSONObject(json); return object.getDouble(key); } catch (Exception e) { e.printStackTrace(); } return null; } public static int getIntValue(String json, String key) {
private int _nextLapseIvl(Card card, JSONObject conf) { try { return Math.max(conf.getInt("minInt"), (int)(card.getIvl() * conf.getDouble("mult"))); } catch (JSONException e) { throw new RuntimeException(e); } }
private ArrayList<LatLng> readItems(int resource) throws JSONException { ArrayList<LatLng> list = new ArrayList<LatLng>(); InputStream inputStream = getResources().openRawResource(resource); String json = new Scanner(inputStream).useDelimiter("\\A").next(); JSONArray array = new JSONArray(json); for (int i = 0; i < array.length(); i++) { JSONObject object = array.getJSONObject(i); double lat = object.getDouble("lat"); double lng = object.getDouble("lng"); list.add(new LatLng(lat, lng)); } return list; }
protected static void parseJSON(JSONObject json, MapObject o) { if (json.has("name")) { o.name = json.getString("name"); } if (json.has("enName")) { o.enName = json.getString("enName"); } if (json.has("names")) { JSONObject namesObj = json.getJSONObject("names"); o.names = new HashMap<>(); Iterator<String> iterator = namesObj.keys(); while (iterator.hasNext()) { String key = iterator.next(); String value = namesObj.getString(key); o.names.put(key, value); } } if (json.has("lat") && json.has("lon")) { o.location = new LatLon(json.getDouble("lat"), json.getDouble("lon")); } if (json.has("id")) { o.id = json.getLong("id"); } } }
public static Result parse(String body) throws Exception { try { JSONObject jsonObject = new JSONObject(body); Result result = new Result(); result.rating = (float)jsonObject.getDouble("rating_avg"); result.ratingCount = jsonObject.getInt("rating_cnt"); return result; } catch (JSONException e) { Exception exception = new ParseException("Can't parse rate gallery", body); exception.initCause(e); throw exception; } } }
public List<MyItem> read(InputStream inputStream) throws JSONException { List<MyItem> items = new ArrayList<MyItem>(); String json = new Scanner(inputStream).useDelimiter(REGEX_INPUT_BOUNDARY_BEGINNING).next(); JSONArray array = new JSONArray(json); for (int i = 0; i < array.length(); i++) { String title = null; String snippet = null; JSONObject object = array.getJSONObject(i); double lat = object.getDouble("lat"); double lng = object.getDouble("lng"); if (!object.isNull("title")) { title = object.getString("title"); } if (!object.isNull("snippet")) { snippet = object.getString("snippet"); } items.add(new MyItem(lat, lng, title, snippet)); } return items; }
private void buildModelMap(String jsonString) throws JSONException { HashMap<AndroidModel, DistanceCalculator> map = new HashMap<AndroidModel, DistanceCalculator>(); JSONObject jsonObject = new JSONObject(jsonString); JSONArray array = jsonObject.getJSONArray("models"); for (int i = 0; i < array.length(); i++) { JSONObject modelObject = array.getJSONObject(i); boolean defaultFlag = false; if (modelObject.has("default")) { defaultFlag = modelObject.getBoolean("default"); } Double coefficient1 = modelObject.getDouble("coefficient1"); Double coefficient2 = modelObject.getDouble("coefficient2"); Double coefficient3 = modelObject.getDouble("coefficient3"); String version = modelObject.getString("version"); String buildNumber = modelObject.getString("build_number"); String model = modelObject.getString("model"); String manufacturer = modelObject.getString("manufacturer"); CurveFittedDistanceCalculator distanceCalculator = new CurveFittedDistanceCalculator(coefficient1,coefficient2,coefficient3); AndroidModel androidModel = new AndroidModel(version, buildNumber, model, manufacturer); map.put(androidModel, distanceCalculator); if (defaultFlag) { mDefaultModel = androidModel; } } mModelMap = map; }
public static SearchSettings parseJSON(JSONObject json) { SearchSettings s = new SearchSettings(new ArrayList<BinaryMapIndexReader>()); if (json.has("lat") && json.has("lon")) { s.originalLocation = new LatLon(json.getDouble("lat"), json.getDouble("lon")); } s.radiusLevel = json.optInt("radiusLevel", 1); s.totalLimit = json.optInt("totalLimit", -1); s.transliterateIfMissing = json.optBoolean("transliterateIfMissing", false); s.emptyQueryAllowed = json.optBoolean("emptyQueryAllowed", false); s.sortByName = json.optBoolean("sortByName", false); if (json.has("lang")) { s.lang = json.getString("lang"); } if (json.has("searchTypes")) { JSONArray searchTypesArr = json.getJSONArray("searchTypes"); ObjectType[] searchTypes = new ObjectType[searchTypesArr.length()]; for (int i = 0; i < searchTypesArr.length(); i++) { String name = searchTypesArr.getString(i); searchTypes[i] = ObjectType.valueOf(name); } s.searchTypes = searchTypes; } return s; } }
public static Building parseJSON(JSONObject json) throws IllegalArgumentException { Building b = new Building(); MapObject.parseJSON(json, b); if (json.has("postcode")) { b.postcode = json.getString("postcode"); } if (json.has("lat2") && json.has("lon2")) { b.latLon2 = new LatLon(json.getDouble("lat2"), json.getDouble("lon2")); } if (json.has("interpolationType")) { b.interpolationType = BuildingInterpolation.valueOf(json.getString("interpolationType")); } if (json.has("interpolationInterval")) { b.interpolationInterval = json.getInt("interpolationInterval"); } if (json.has("name2")) { b.name2 = json.getString("name2"); } return b; } }
private JSONObject _lapseConf(Card card) { try { JSONObject conf = _cardConf(card); // normal deck if (card.getODid() == 0) { return conf.getJSONObject("lapse"); } // dynamic deck; override some attributes, use original deck for others JSONObject oconf = mCol.getDecks().confForDid(card.getODid()); JSONArray delays = conf.optJSONArray("delays"); if (delays == null) { delays = oconf.getJSONObject("lapse").getJSONArray("delays"); } JSONObject dict = new JSONObject(); // original deck dict.put("minInt", oconf.getJSONObject("lapse").getInt("minInt")); dict.put("leechFails", oconf.getJSONObject("lapse").getInt("leechFails")); dict.put("leechAction", oconf.getJSONObject("lapse").getInt("leechAction")); dict.put("mult", oconf.getJSONObject("lapse").getDouble("mult")); // overrides dict.put("delays", delays); dict.put("resched", conf.getBoolean("resched")); return dict; } catch (JSONException e) { throw new RuntimeException(e); } }
mValues.put("easyBonus", Integer.toString((int) (revOptions.getDouble("ease4") * 100))); mValues.put("revIvlFct", Integer.toString((int) (revOptions.getDouble("ivlFct") * 100))); mValues.put("revMaxIvl", revOptions.getString("maxIvl")); mValues.put("revBury", Boolean.toString(revOptions.optBoolean("bury", true))); mValues.put("lapNewIvl", Integer.toString((int) (lapOptions.getDouble("mult") * 100))); mValues.put("lapMinIvl", lapOptions.getString("minInt")); mValues.put("lapLeechThres", lapOptions.getString("leechFails"));
assertEquals(7, json.getInt("intValue")); assertEquals(5000000000l, json.getLong("longValue")); assertEquals(3.14, json.getDouble("doubleValue"), TestUtils.DOUBLE_EQUALS_DELTA); assertEquals("hello world", json.getString("stringValue"));
/** * Ideal next interval for CARD, given EASE. */ private int _nextRevIvl(Card card, int ease) { try { long delay = _daysLate(card); int interval = 0; JSONObject conf = _revConf(card); double fct = card.getFactor() / 1000.0; int ivl2 = _constrainedIvl((int)((card.getIvl() + delay/4) * 1.2), conf, card.getIvl()); int ivl3 = _constrainedIvl((int)((card.getIvl() + delay/2) * fct), conf, ivl2); int ivl4 = _constrainedIvl((int)((card.getIvl() + delay) * fct * conf.getDouble("ease4")), conf, ivl3); if (ease == 2) { interval = ivl2; } else if (ease == 3) { interval = ivl3; } else if (ease == 4) { interval = ivl4; } // interval capped? return Math.min(interval, conf.getInt("maxIvl")); } catch (JSONException e) { throw new RuntimeException(e); } }
testObject.getW_bool().booleanValue(), jsonObject.getBoolean(testObject.getW_boolFN())); Assert.assertEquals("VerifyPdxInstanceToJson: Float type values are not matched", testObject.getW_double().doubleValue(), jsonObject.getDouble(testObject.getW_doubleFN()), 0); Assert.assertEquals("VerifyPdxInstanceToJson: bigDec type values are not matched",