Java Code Examples for org.json.JSONObject#optDouble()
The following examples show how to use
org.json.JSONObject#optDouble() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MarketsRespone.java From RipplePower with Apache License 2.0 | 7 votes |
public void from(Object obj) { if (obj != null) { if (obj instanceof JSONObject) { JSONObject result = (JSONObject) obj; this.rowkey = result.optString("rowkey"); this.count = result.optLong("count"); this.startTime = result.optString("startTime"); this.endTime = result.optString("endTime"); this.exchange.copyFrom(result.opt("exchange")); this.exchangeRate = result.optDouble("exchangeRate"); this.total = result.optDouble("total"); JSONArray arrays = result.optJSONArray("components"); if (arrays != null) { int size = arrays.length(); for (int i = 0; i < size; i++) { MarketComponent marketComponent = new MarketComponent(); marketComponent.from(arrays.getJSONObject(i)); components.add(marketComponent); } } } } }
Example 2
Source File: ITeslaRules.java From ipst with Mozilla Public License 2.0 | 6 votes |
public static void processTreeNode(JSONObject node, JSONArray inputs, String currentCondition, List<String> trueConditions, JSONObject stats, int trueIdx) { if ("thresholdTest".equals(node.optString("type"))) { int inputIdx = node.optInt("inputIndex"); // conditional node String trueCondition = "("+inputs.opt(inputIdx)+" < "+node.optDouble("threshold")+")"; String falseCondition = "("+inputs.opt(inputIdx)+" >= "+node.optDouble("threshold")+")"; processTreeNode(node.optJSONObject("trueChild"), inputs, (currentCondition==null||currentCondition.length()==0)?trueCondition:(currentCondition+" and "+trueCondition), trueConditions, stats, trueIdx); processTreeNode(node.optJSONObject("falseChild"), inputs, (currentCondition==null||currentCondition.length()==0)?falseCondition:(currentCondition+" and "+falseCondition), trueConditions, stats, trueIdx); } else { String nodeIdx = node.optString("id"); JSONArray nodeValues = stats.optJSONObject(nodeIdx).optJSONArray("counts"); double purity = nodeValues.optInt(trueIdx) / (double)stats.optJSONObject(nodeIdx).optInt("count"); if (purity > 0.95 && node.optBoolean("value")) { trueConditions.add(currentCondition == null ? "true" : currentCondition); } } }
Example 3
Source File: Bestiary.java From remixed-dungeon with GNU General Public License v3.0 | 6 votes |
public static void selfTest(JSONObject root) { Iterator<String> keyI = root.keys(); while (keyI.hasNext()) { String key = keyI.next(); if(key.equals("Chance")) { continue; } double chances = root.optDouble(key,-1); if(chances>0) { if(!MobFactory.hasMob(key)) { ModError.doReport("missing mob class: "+key+" found in Bestiary.json", new Exception()); } continue; } JSONObject childObject = root.optJSONObject(key); if(childObject!=null) { selfTest(childObject); } } }
Example 4
Source File: TotalNetworkValue.java From RipplePower with Apache License 2.0 | 6 votes |
public void from(JSONObject obj) { if (obj != null) { this.currency = obj.optString("currency"); this.issuer = obj.optString("issuer"); this.name = obj.optString("name"); this.amount = obj.optDouble("amount"); this.convertedAmount = obj.optDouble("convertedAmount"); this.rate = obj.optDouble("rate"); JSONArray arrays = obj.optJSONArray("hotwallets"); if (arrays != null) { int size = arrays.length(); for (int i = 0; i < size; i++) { String hotwallet = arrays.getString(i); hotwallets.add(hotwallet); } } } }
Example 5
Source File: Ask.java From RipplePower with Apache License 2.0 | 6 votes |
public void from(JSONObject obj) { if (obj != null) { this.owner_funds = obj.optString("owner_funds"); this.Account = obj.optString("Account"); this.PreviousTxnLgrSeq = obj.optLong("PreviousTxnLgrSeq"); this.OwnerNode = obj.optString("OwnerNode"); this.index = obj.optString("index"); this.PreviousTxnID = obj.optString("PreviousTxnID"); this.TakerGets.from(obj.opt("TakerGets")); this.TakerPays.from(obj.opt("TakerPays")); this.Flags = obj.optInt("Flags"); this.Sequence = obj.optLong("Sequence"); this.quality = obj.optString("quality"); this.BookDirectory = obj.optString("BookDirectory"); this.LedgerEntryType = obj.optString("LedgerEntryType"); this.BookNode = obj.optString("BookNode"); this.Amount = obj.optDouble("Amount"); if (Amount <= 0) { Amount = Double.parseDouble(quality); } } }
Example 6
Source File: Carb.java From HAPP with GNU General Public License v3.0 | 6 votes |
public String isActive(Profile profile, Realm realm){ JSONObject cobDetails = Carb.getCOBBetween(profile, new Date(timestamp.getTime() - (8 * 60 * 60000)), timestamp, realm); //last 8 hours if (cobDetails.optDouble("cob", 0) > 0) { //Still active carbs String isLeft; if (cobDetails.optDouble("cob", 0) > this.value) { isLeft = tools.formatDisplayCarbs(this.value); } else { isLeft = tools.formatDisplayCarbs(cobDetails.optDouble("cob", 0)); } String timeLeft = tools.formatDisplayTimeLeft(new Date(), new Date(cobDetails.optLong("decayedBy", 0))); return isLeft + " " + timeLeft + " remaining"; } else { //Not active return "Not Active"; } }
Example 7
Source File: TextElement.java From cidrawing with Apache License 2.0 | 5 votes |
@Override public void loadFromJson(JSONObject object, Map<String, byte[]> resources) { super.loadFromJson(object, resources); if (object != null) { text = object.optString(KEY_TEXT, ""); textSize = (float) object.optDouble(KEY_SIZE); } }
Example 8
Source File: AccountOffersResult.java From RipplePower with Apache License 2.0 | 5 votes |
public void from(JSONObject obj) { if (obj != null) { this.base.from(obj.opt("base")); this.counter.from(obj.opt("counter")); this.type = obj.optString("type"); this.rate = obj.optDouble("rate"); this.counterparty = obj.optString("counterparty"); this.time = obj.optString("time"); this.txHash = obj.optString("txHash"); this.ledgerIndex = obj.optLong("ledgerIndex"); } }
Example 9
Source File: DisplayWindow.java From marathonv5 with Apache License 2.0 | 5 votes |
public void setWindowState() { JSONObject p = Preferences.instance().getSection("display"); if (p.optBoolean("maximized")) setMaximized(true); else if (p.optBoolean("fullscreen")) setFullScreen(true); else { double x = p.optDouble("window.x", 0); double y = p.optDouble("window.y", 0); double w = p.optDouble("window.w", 1280); double h = p.optDouble("window.h", 1024); if (x < 0) x = 0; if (y < 0) y = 0; if (w < 0) w = 1280; if (h < 0) h = 1024; setWidth(w); setHeight(h); setX(x); setY(y); if (p.optBoolean("iconified")) setIconified(true); } }
Example 10
Source File: AirMapLayerStyle.java From AirMapSDK-Android with Apache License 2.0 | 5 votes |
AirMapLayerStyle(JSONObject json) { id = optString(json, "id"); source = optString(json, "source"); sourceLayer = optString(json, "source-layer"); type = optString(json, "type"); minZoom = (float) json.optDouble("minzoom", 0); }
Example 11
Source File: JsonDemo.java From java-tutorial with MIT License | 5 votes |
private static Object jsonObjectToObject(JSONObject obj, Field field) throws JSONException { //field.getType:获取属性声明时类型对象(返回class对象) switch (getType(field.getType())) { case 0: return obj.opt(field.getName()); case 1: return obj.optInt(field.getName()); case 2: return obj.optLong(field.getName()); case 3: case 4: return obj.optDouble(field.getName()); case 5: return obj.optBoolean(field.getName()); case 6: case 7: //JsonArray型 case 8: return obj.optJSONArray(field.getName()); case 9: return jsonArrayToList(obj.optJSONArray(field.getName())); case 10: return jsonObjectToMap(obj.optJSONObject(field.getName())); default: return null; } }
Example 12
Source File: VKApiPoll.java From cordova-social-vk with Apache License 2.0 | 5 votes |
public Answer parse(JSONObject source) { id = source.optInt("id"); text = source.optString("text"); votes = source.optInt("votes"); rate = source.optDouble("rate"); return this; }
Example 13
Source File: StatisticParameters.java From open-rmbt with Apache License 2.0 | 4 votes |
public StatisticParameters(String defaultLang, String params) { String _lang = defaultLang; float _quantile = 0.5f; // median is default quantile int _duration = 90; int _maxDevices = 100; String _type = "mobile"; String _networkTypeGroup = null; double _accuracy = -1; String _country = null; boolean _userServerSelection = false; java.sql.Timestamp _endDate = null; int _province = -1; if (params != null && !params.isEmpty()) // try parse the string to a JSON object try { final JSONObject request = new JSONObject(params); _lang = request.optString("language" , _lang); final double __quantile = request.optDouble("quantile", Double.NaN); if (__quantile >= 0 && __quantile <= 1) _quantile = (float) __quantile; final int __months = request.optInt("months", 0); // obsolete, old format (now in days) if (__months > 0) _duration = __months * 30; final int __duration = request.optInt("duration", 0); if (__duration > 0) _duration = __duration; final int __maxDevices = request.optInt("max_devices", 0); if (__maxDevices > 0) _maxDevices = __maxDevices; final String __type = request.optString("type", null); if (__type != null) _type = __type; final String __networkTypeGroup = request.optString("network_type_group", null); if (__networkTypeGroup != null && ! __networkTypeGroup.equalsIgnoreCase("all")) _networkTypeGroup = __networkTypeGroup; final double __accuracy = request.optDouble("location_accuracy",-1); if (__accuracy != -1) _accuracy = __accuracy; final String __country = request.optString("country", null); if (__country != null && __country.length() == 2) _country = __country; _userServerSelection = request.optBoolean("user_server_selection"); // It returns false if there is no such key, or if the value is not Boolean.TRUE or the String "true". final String __endDateString = request.optString("end_date", null); if (__endDateString != null) { final java.sql.Timestamp __endDate = parseSqlTimestamp(__endDateString); _endDate = __endDate; } final int __province = request.optInt("province", 0); if (__province > 0) _province = __province; } catch (final JSONException e) { } lang = _lang; quantile = _quantile; duration = _duration; maxDevices = _maxDevices; type = _type; networkTypeGroup = _networkTypeGroup; accuracy = _accuracy; country = _country; userServerSelection = _userServerSelection; endDate = _endDate; province = _province; }
Example 14
Source File: TgVoip.java From Telegram with GNU General Public License v2.0 | 4 votes |
private ServerConfig(JSONObject jsonObject) { this.jsonObject = jsonObject; this.useSystemNs = jsonObject.optBoolean("use_system_ns", true); this.useSystemAec = jsonObject.optBoolean("use_system_aec", true); this.hangupUiTimeout = jsonObject.optDouble("hangup_ui_timeout", 5); }
Example 15
Source File: AirMapStatusAdvisory.java From AirMapSDK-Android with Apache License 2.0 | 4 votes |
@Override public AirMapStatusAdvisory constructFromJson(JSONObject json) { if (json != null) { setId(optString(json, "id")); setName(optString(json, "name")); setOrganizationId(optString(json, "organization_id")); setRequirements(new AirMapStatusRequirement(json.optJSONObject("requirements"))); String typeString = optString(json, "type"); setType(MappingService.AirMapAirspaceType.fromString(typeString)); setCountry(optString(json, "country")); setDistance(json.optInt("distance")); setCity(optString(json, "city")); setState(optString(json, "state")); setColor(AirMapColor.fromString(optString(json, "color"))); setGeometryString(optString(json, "geometry")); double lat = json.optDouble("latitude"); double lng = json.optDouble("longitude"); if (lat != Double.NaN && lng != Double.NaN) { setCoordinate(new Coordinate(lat, lng)); } setLastUpdated(getDateFromIso8601String(optString(json, "last_updated"))); JSONObject properties = json.optJSONObject("properties"); if (type == MappingService.AirMapAirspaceType.Airport) { setAirportProperties(new AirMapAirportProperties(properties)); } else if (type == MappingService.AirMapAirspaceType.Park) { setParkProperties(new AirMapParkProperties(properties)); } else if (type == MappingService.AirMapAirspaceType.SpecialUse) { setSpecialUseProperties(new AirMapSpecialUseProperties(properties)); } else if (type == MappingService.AirMapAirspaceType.PowerPlant) { setPowerPlantProperties(new AirMapPowerPlantProperties(properties)); } else if (type == MappingService.AirMapAirspaceType.ControlledAirspace) { setControlledAirspaceProperties(new AirMapControlledAirspaceProperties(properties)); } else if (type == MappingService.AirMapAirspaceType.School) { setSchoolProperties(new AirMapSchoolProperties(properties)); } else if (type == MappingService.AirMapAirspaceType.TFR) { setTfrProperties(new AirMapTfrProperties(properties)); } else if (type == MappingService.AirMapAirspaceType.Wildfires || type == MappingService.AirMapAirspaceType.Fires) { setWildfireProperties(new AirMapWildfireProperties(properties)); } else if (type == MappingService.AirMapAirspaceType.Heliport) { setHeliportProperties(new AirMapHeliportProperties(properties)); } else if (type == MappingService.AirMapAirspaceType.Emergencies) { setEmergencyProperties(new AirMapEmergencyProperties(properties)); } } return this; }
Example 16
Source File: Layer.java From atlas with Apache License 2.0 | 4 votes |
static Layer newInstance(JSONObject json, LottieComposition composition) { String layerName = json.optString("nm"); String refId = json.optString("refId"); long layerId = json.optLong("ind"); int solidWidth = 0; int solidHeight = 0; int solidColor = 0; int preCompWidth = 0; int preCompHeight = 0; LayerType layerType; int layerTypeInt = json.optInt("ty", -1); if (layerTypeInt < LayerType.Unknown.ordinal()) { layerType = LayerType.values()[layerTypeInt]; } else { layerType = LayerType.Unknown; } long parentId = json.optLong("parent", -1); if (layerType == LayerType.Solid) { solidWidth = (int) (json.optInt("sw") * composition.getDpScale()); solidHeight = (int) (json.optInt("sh") * composition.getDpScale()); solidColor = Color.parseColor(json.optString("sc")); if (L.DBG) { Log.d(TAG, "\tSolid=" + Integer.toHexString(solidColor) + " " + solidWidth + "x" + solidHeight + " " + composition.getBounds()); } } AnimatableTransform transform = AnimatableTransform.Factory.newInstance(json.optJSONObject("ks"), composition); MatteType matteType = MatteType.values()[json.optInt("tt")]; List<Object> shapes = new ArrayList<>(); List<Mask> masks = new ArrayList<>(); List<Keyframe<Float>> inOutKeyframes = new ArrayList<>(); JSONArray jsonMasks = json.optJSONArray("masksProperties"); if (jsonMasks != null) { for (int i = 0; i < jsonMasks.length(); i++) { Mask mask = Mask.Factory.newMask(jsonMasks.optJSONObject(i), composition); masks.add(mask); } } JSONArray shapesJson = json.optJSONArray("shapes"); if (shapesJson != null) { for (int i = 0; i < shapesJson.length(); i++) { Object shape = ShapeGroup.shapeItemWithJson(shapesJson.optJSONObject(i), composition); if (shape != null) { shapes.add(shape); } } } float timeStretch = (float) json.optDouble("sr", 1.0); float startFrame = (float) json.optDouble("st"); float frames = composition.getDurationFrames(); float startProgress = startFrame / frames; if (layerType == LayerType.PreComp) { preCompWidth = (int) (json.optInt("w") * composition.getDpScale()); preCompHeight = (int) (json.optInt("h") * composition.getDpScale()); } float inFrame = json.optLong("ip"); float outFrame = json.optLong("op"); // Before the in frame if (inFrame > 0) { Keyframe<Float> preKeyframe = new Keyframe<>(composition, 0f, 0f, null, 0f, inFrame); inOutKeyframes.add(preKeyframe); } // The + 1 is because the animation should be visible on the out frame itself. outFrame = (outFrame > 0 ? outFrame : composition.getEndFrame() + 1); Keyframe<Float> visibleKeyframe = new Keyframe<>(composition, 1f, 1f, null, inFrame, outFrame); inOutKeyframes.add(visibleKeyframe); if (outFrame <= composition.getDurationFrames()) { Keyframe<Float> outKeyframe = new Keyframe<>(composition, 0f, 0f, null, outFrame, (float) composition.getEndFrame()); inOutKeyframes.add(outKeyframe); } return new Layer(shapes, composition, layerName, layerId, layerType, parentId, refId, masks, transform, solidWidth, solidHeight, solidColor, timeStretch, startProgress, preCompWidth, preCompHeight, inOutKeyframes, matteType); }
Example 17
Source File: KanboardTask.java From Kandroid with GNU General Public License v3.0 | 4 votes |
public KanboardTask(JSONObject json) throws MalformedURLException { ID = json.optInt("id", -1); ProjectID = json.optInt("project_id", -1); ColumnID = json.optInt("column_id", -1); SwimlaneID = json.optInt("swimlane_id", -1); CategoryID = json.optInt("category_id", -1); CreatorID = json.optInt("creator_id", -1); OwnerID = json.optInt("owner_id", -1); Priority = json.optInt("priority", -1); Position = json.optInt("position", -1); IsActive = KanboardAPI.StringToBoolean(json.optString("is_active")); Title = json.optString("title"); Description = json.optString("description"); if (json.has("url")) Url = new URL(json.optString("url")); else Url = null; TimeEstimated = json.optDouble("time_estimated"); TimeSpent = json.optDouble("time_spent"); // Dashboard properties ProjectName = json.optString("project_name"); ColumnTitle = json.optString("column_title"); long tmpTime = json.optLong("date_due"); // Kanboard returns 0 when there was no time set if (tmpTime > 0) DueDate = new Date(tmpTime * 1000); else DueDate = null; tmpTime = json.optLong("date_completed"); if (tmpTime > 0) CompletedDate = new Date(tmpTime * 1000); else CompletedDate = null; tmpTime = json.optLong("date_started"); if (tmpTime > 0) StartedDate = new Date(tmpTime * 1000); else StartedDate = null; tmpTime = json.optLong("date_creation"); if (tmpTime > 0) CreationDate = new Date(tmpTime * 1000); else CreationDate = null; tmpTime = json.optLong("date_modification"); if (tmpTime > 0) ModificationDate = new Date(tmpTime * 1000); else ModificationDate = null; tmpTime = json.optLong("date_moved"); if (tmpTime > 0) MovedDate = new Date(tmpTime * 1000); else MovedDate = null; ColorId = json.optString("color_id", ""); if (json.has("color")) ColorBackground = KanboardAPI.parseColorString(json.optJSONObject("color").optString("background")); }
Example 18
Source File: InputConverter.java From react-native-image-filter-kit with MIT License | 4 votes |
private PointF extractOffset(@Nullable JSONObject offset, @Nonnull PointF defaultValue) { return new PointF( offset != null ? (float) offset.optDouble("x", defaultValue.x) : defaultValue.x, offset != null ? (float) offset.optDouble("y", defaultValue.y) : defaultValue.y ); }
Example 19
Source File: FloatParser.java From react-native-navigation with MIT License | 4 votes |
public static FloatParam parse(JSONObject json, String number) { return json.has(number) ? new FloatParam((float) json.optDouble(number)) : new NullFloatParam(); }
Example 20
Source File: MesosResourceUsageUtils.java From mantis with Apache License 2.0 | 4 votes |
private Usage getCurentUsage(String taskId, String usageJson) { if (usageJson == null || usageJson.isEmpty()) return null; JSONArray array = new JSONArray(usageJson); if (array.length() == 0) return null; JSONObject obj = null; for (int i = 0; i < array.length(); i++) { JSONObject executor = array.getJSONObject(i); if (executor != null) { String id = executor.optString("executor_id"); if (id != null && id.equals(taskId)) { obj = executor.getJSONObject("statistics"); break; } } } if (obj == null) return null; double cpus_limit = obj.optDouble("cpus_limit"); if (Double.isNaN(cpus_limit)) { cpus_limit = 0.0; } double cpus_system_time_secs = obj.optDouble("cpus_system_time_secs"); if (Double.isNaN(cpus_system_time_secs)) { logger.warn("Didn't get cpus_system_time_secs from mesos stats"); cpus_system_time_secs = 0.0; } double cpus_user_time_secs = obj.optDouble("cpus_user_time_secs"); if (Double.isNaN(cpus_user_time_secs)) { logger.warn("Didn't get cpus_user_time_secs from mesos stats"); cpus_user_time_secs = 0.0; } // Also, cpus_throttled_time_secs may be useful to notice when job is throttled, will look into it later double mem_rss_bytes = obj.optDouble("mem_rss_bytes"); if (Double.isNaN(mem_rss_bytes)) { logger.warn("Couldn't get mem_rss_bytes from mesos stats"); mem_rss_bytes = 0.0; } double mem_anon_bytes = obj.optDouble("mem_anon_bytes"); if (Double.isNaN(mem_anon_bytes)) { mem_anon_bytes = mem_rss_bytes; } double mem_limit = obj.optDouble("mem_limit_bytes"); if (Double.isNaN(mem_limit)) mem_limit = 0.0; double network_limit = OneGbInBytes; double network_read_bytes = obj.optDouble("net_rx_bytes"); if (Double.isNaN(network_read_bytes)) network_read_bytes = 0.0; double network_write_bytes = obj.optDouble("net_tx_bytes"); if (Double.isNaN(network_write_bytes)) network_write_bytes = 0.0; return new Usage(cpus_limit, cpus_system_time_secs, cpus_user_time_secs, mem_limit, mem_rss_bytes, mem_anon_bytes, network_limit, network_read_bytes, network_write_bytes); }