本文整理了Java中org.json.JSONObject.getDouble()
方法的一些代码示例,展示了JSONObject.getDouble()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONObject.getDouble()
方法的具体详情如下:
包路径:org.json.JSONObject
类名称:JSONObject
方法名:getDouble
[英]Returns the value mapped by name if it exists and is a double or can be coerced to a double.
[中]返回按名称映射的值(如果该值存在且为双精度值或可以强制为双精度值)。
代码示例来源:origin: google/physical-web
/**
* 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);
}
代码示例来源:origin: google/physical-web
/**
* 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);
}
代码示例来源:origin: zzz40500/GsonFormat
/**
* 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;
}
}
代码示例来源:origin: jaydenxiao2016/AndroidFire
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) {
代码示例来源:origin: ankidroid/Anki-Android
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);
}
}
代码示例来源:origin: googlemaps/android-maps-utils
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;
}
代码示例来源:origin: osmandapp/Osmand
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");
}
}
}
代码示例来源:origin: seven332/EhViewer
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;
}
}
}
代码示例来源:origin: stackoverflow.com
System.out.println(person.getString("name"));
System.out.println(person.getString("gender"));
System.out.println(person.getDouble("latitude"));
System.out.println(person.getDouble("longitude"));
代码示例来源:origin: googlemaps/android-maps-utils
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;
}
代码示例来源:origin: AltBeacon/android-beacon-library
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;
}
代码示例来源:origin: osmandapp/Osmand
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;
}
}
代码示例来源:origin: osmandapp/Osmand
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;
}
}
代码示例来源:origin: googlemaps/android-maps-utils
.getJSONObject("geometry").getJSONObject("location");
results.put(pointsJsonArray.getJSONObject(i).getString("id"),
new LatLng(location.getDouble("lat"),
location.getDouble("lng")));
代码示例来源:origin: ankidroid/Anki-Android
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);
}
}
代码示例来源:origin: ankidroid/Anki-Android
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"));
代码示例来源:origin: stackoverflow.com
final GeoPoint position = new GeoPoint((int) (start.getDouble("lat")*1E6),
(int) (start.getDouble("lng")*1E6));
segment.setPoint(position);
代码示例来源:origin: facebook/facebook-android-sdk
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"));
代码示例来源:origin: ankidroid/Anki-Android
/**
* 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);
}
}
代码示例来源:origin: apache/geode
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",
内容来源于网络,如有侵权,请联系作者删除!