本文整理汇总了Java中org.json.JSONObject.optDouble方法的典型用法代码示例。如果您正苦于以下问题:Java JSONObject.optDouble方法的具体用法?Java JSONObject.optDouble怎么用?Java JSONObject.optDouble使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.json.JSONObject
的用法示例。
在下文中一共展示了JSONObject.optDouble方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: wrapExposureConfig
import org.json.JSONObject; //导入方法依赖的package包/类
private void wrapExposureConfig(String configStr) {
if (TextUtils.isEmpty(configStr)) {
return;
}
try {
JSONObject jsonObject = new JSONObject(configStr);
GlobalsContext.trackerExposureOpen = jsonObject.optBoolean("masterSwitch", true);
GlobalsContext.timeThreshold = jsonObject.optInt("timeThreshold", 100);
GlobalsContext.dimThreshold = jsonObject.optDouble("dimThreshold", 0.8);
GlobalsContext.exposureSampling = jsonObject.optInt("exposureSampling", 100);
GlobalsContext.batchOpen = jsonObject.optBoolean("batchOpen", false);
TrackerLog.v("ConfigReceiver trackerExposureConfig " + jsonObject.toString());
} catch (JSONException e) {
TrackerLog.e("ConfigReceiver wrapExposureConfig fail " + e.getMessage());
}
}
示例2: DialogOutput
import org.json.JSONObject; //导入方法依赖的package包/类
public DialogOutput(JSONObject json) {
mGuid = json.optString(Keys.Guid);
mText = json.optString(Keys.Text);
mAudioUri = json.optString(Keys.Uri);
mVideoUri = json.optString(Keys.VideoFile);
mCharacter = json.optString(Keys.Character);
mDuration = json.optDouble(Keys.Duration, 0);
mUserData = json.optString(Keys.UserData);
JSONArray phonemeJson = json.optJSONArray(Keys.Phonemes);
if (phonemeJson != null && phonemeJson.length() > 0) {
mPhonemes = new ArrayList<>();
for (int i = 0; i < phonemeJson.length(); i++) {
JSONObject p = phonemeJson.optJSONObject(i);
if (p != null) {
Phoneme phoneme = new Phoneme(p);
mPhonemes.add(phoneme);
}
}
}
}
示例3: setWindowState
import org.json.JSONObject; //导入方法依赖的package包/类
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);
}
}
示例4: parse
import org.json.JSONObject; //导入方法依赖的package包/类
public static Coordinate parse(JSONObject jsonObject) {
if (jsonObject == null) {
return null;
}
Coordinate coordinate = new Coordinate();
coordinate.Longtitude = jsonObject.optDouble("longitude");
coordinate.Latitude = jsonObject.optDouble("latitude");
return coordinate;
}
示例5: LeadTimeAvgConfig
import org.json.JSONObject; //导入方法依赖的package包/类
public LeadTimeAvgConfig(JSONObject json) {
if (json != null) {
minNumOfOrders = json.optInt(MINIMUM_NUMBER_OF_ORDERS, this.minNumOfOrders);
maxNumOfOrders = json.optInt(MAXIMUM_NUMBER_OF_ORDERS, this.maxNumOfOrders);
maxOrderPeriods = new Float(json.optDouble(MAXIMUM_ORDER_PERIODS, this.maxOrderPeriods));
excludeOrdProcTime =
json.optBoolean(EXCLUDE_ORDER_PROCESSING_TIME_FROM_LEADTIME_COMPUTATION,
this.excludeOrdProcTime);
}
}
示例6: parseStyle
import org.json.JSONObject; //导入方法依赖的package包/类
@Override
public void parseStyle(@Nullable JSONObject data) {
super.parseStyle(data);
if (data == null)
return;
cell.setIndicatorRadius(Style.dp2px(data.optDouble(ATTR_INDICATOR_RADIUS)));
cell.setIndicatorColor(Style.parseColor(data.optString(ATTR_INDICATOR_COLOR, "#00000000")));
cell.setIndicatorDefaultColor(Style.parseColor(data.optString(ATTR_INDICATOR_DEFAULT_INDICATOR_COLOR, "#00000000")));
cell.setAutoScrollInternal(data.optInt(ATTR_AUTOSCROLL));
cell.setSpecialInterval(data.optJSONObject(ATTR_SPECIAL_INTERVAL));
cell.setInfinite(data.optBoolean(ATTR_INFINITE));
cell.setInfiniteMinCount(data.optInt(ATTR_INFINITE_MIN_COUNT));
cell.setIndicatorFocus(data.optString(ATTR_INDICATOR_FOCUS));
cell.setIndicatorNor(data.optString(ATTR_INDICATOR_NORMAL));
cell.setIndicatorGravity(data.optString(ATTR_INDICATOR_GRA));
cell.setIndicatorPos(data.optString(ATTR_INDICATOR_POS));
cell.setIndicatorGap(Style.dp2px(data.optInt(ATTR_INDICATOR_GAP)));
cell.setIndicatorMargin(Style.dp2px(data.optInt(ATTR_INDICATOR_MARGIN)));
cell.setIndicatorHeight(Style.dp2px(data.optInt(ATTR_INDICATOR_HEIGHT)));
cell.setPageWidth(data.optDouble(ATTR_PAGE_WIDTH));
cell.sethGap(Style.dp2px(data.optInt(ATTR_HGAP)));
cell.itemRatio = data.optDouble(BannerCard.ATTR_ITEM_RATIO, Double.NaN);
cell.itemMargin[0] = Style.dp2px(data.optInt(ATTR_ITEM_MARGIN_LEFT));
cell.itemMargin[1] = Style.dp2px(data.optInt(ATTR_ITEM_MARGIN_RIGHT));
if (style != null) {
cell.setRatio(style.aspectRatio);
cell.margin = style.margin;
}
}
示例7: parseStyle
import org.json.JSONObject; //导入方法依赖的package包/类
@Override
public void parseStyle(@Nullable JSONObject data) {
style = new Style();
style.parseWith(data);
setRatio(style.aspectRatio);
if (style.bgColor == 0) {
setBgColor(Color.WHITE);
} else {
setBgColor(style.bgColor);
}
margin = style.margin;
if (margin != null) {
for (int i = 0; i < margin.length; i++) {
if (margin[i] < 0) {
margin[i] = 0;
}
}
}
if (data != null) {
setIndicatorRadius(Style.dp2px(data.optDouble(BannerCard.ATTR_INDICATOR_RADIUS)));
setIndicatorColor(Style.parseColor(data.optString(BannerCard.ATTR_INDICATOR_COLOR, "#00000000")));
setIndicatorDefaultColor(Style.parseColor(data.optString(BannerCard.ATTR_INDICATOR_DEFAULT_INDICATOR_COLOR, "#00000000")));
setAutoScrollInternal(data.optInt(BannerCard.ATTR_AUTOSCROLL));
setSpecialInterval(data.optJSONObject(BannerCard.ATTR_SPECIAL_INTERVAL));
setInfinite(data.optBoolean(BannerCard.ATTR_INFINITE));
setInfiniteMinCount(data.optInt(BannerCard.ATTR_INFINITE_MIN_COUNT));
setIndicatorFocus(data.optString(BannerCard.ATTR_INDICATOR_FOCUS));
setIndicatorNor(data.optString(BannerCard.ATTR_INDICATOR_NORMAL));
setIndicatorGravity(data.optString(BannerCard.ATTR_INDICATOR_GRA));
setIndicatorPos(data.optString(BannerCard.ATTR_INDICATOR_POS));
setIndicatorGap(Style.dp2px(data.optInt(BannerCard.ATTR_INDICATOR_GAP)));
setIndicatorMargin(Style.dp2px(data.optInt(BannerCard.ATTR_INDICATOR_MARGIN)));
setIndicatorHeight(Style.dp2px(data.optInt(BannerCard.ATTR_INDICATOR_HEIGHT)));
setPageWidth(data.optDouble(BannerCard.ATTR_PAGE_WIDTH));
sethGap(Style.dp2px(data.optInt(BannerCard.ATTR_HGAP)));
itemMargin[0] = Style.dp2px(data.optInt(BannerCard.ATTR_ITEM_MARGIN_LEFT));
itemMargin[1] = Style.dp2px(data.optInt(BannerCard.ATTR_ITEM_MARGIN_RIGHT));
itemRatio = data.optDouble(BannerCard.ATTR_ITEM_RATIO, Double.NaN);
}
}
示例8: Phoneme
import org.json.JSONObject; //导入方法依赖的package包/类
public Phoneme(JSONObject json) {
if (json.has(Keys.Name)) {
mName = json.optString(Keys.Name);
}
if (json.has(Keys.SecondsSinceStart)) {
mSecondsSinceStart = json.optDouble(Keys.SecondsSinceStart, 0);
}
}
示例9: from
import org.json.JSONObject; //导入方法依赖的package包/类
@NonNull
static SpeechRecognitionAlternative from(@NonNull JSONObject jsonObject) {
return new SpeechRecognitionAlternative(
jsonObject.optString("transcript", ""),
jsonObject.optDouble("confidence", 0.0)
);
}
示例10: parseEating
import org.json.JSONObject; //导入方法依赖的package包/类
private void parseEating(JSONObject eating) {
int i = 0;
String[] keys = new String[]{"breakfast", "lunch", "dinner", DietShareEatItem.SNACK};
this.viewDietEat.removeAllViews();
int length = keys.length;
while (i < length) {
String key = keys[i];
JSONObject object = eating.optJSONObject(key);
int calory = object.optInt("calory");
if (calory > 0) {
String details = object.optString("details");
DietShareEatItem item = new DietShareEatItem(this);
item.setIcon(key);
item.setTitle(String.valueOf(calory));
item.setUnit("千卡");
item.setSubTitle(details);
try {
double percentage = object.optDouble("percentage");
String description = object.getString("description");
if (!(TextUtils.isEmpty(description) || description.equals("null"))) {
item.setIndicateTextWithString(description);
}
} catch (JSONException e) {
try {
e.printStackTrace();
} catch (Exception e2) {
e2.printStackTrace();
return;
}
}
this.viewDietEat.addView(item);
}
i++;
}
}
示例11: onCreate
import org.json.JSONObject; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Entity$$CREATOR.create("", false);
limitJsonTv = (TextView) findViewById(R.id.limitjson_ms);
try {
JSONObject root = new JSONObject("");
root.opt("");
root.optInt("");
root.optBoolean("");
root.optLong("");
float aa = (float) root.optDouble("");
root.optString("");
root.optJSONObject("");
root.optJSONArray("");
int[] a;
if (root.has("arr")) {
JSONArray array = root.optJSONArray("");
int size = array.length();
a = new int[size];
for (int i = 0; i < size; i++) {
a[i] = array.optInt(i);
}
}
} catch (JSONException e) {
e.printStackTrace();
}
testLimitJson();
LinearGraphView tu = (LinearGraphView) findViewById(R.id.line_graphic);
ArrayList<Double> yList = new ArrayList<Double>();
yList.add((double) 2.103);
yList.add(4.05);
yList.add(6.60);
yList.add(3.08);
yList.add(4.32);
yList.add(2.0);
yList.add(1115.0);
ArrayList<String> xRawDatas = new ArrayList<String>();
xRawDatas.add("05-19");
xRawDatas.add("05-20");
xRawDatas.add("05-21");
xRawDatas.add("05-22");
xRawDatas.add("05-23");
xRawDatas.add("05-24");
xRawDatas.add("05-25");
xRawDatas.add("05-26");
tu.setData(yList, xRawDatas, 8, 2);
}
示例12: newInstance
import org.json.JSONObject; //导入方法依赖的package包/类
static <T> Keyframe<T> newInstance(JSONObject json, LottieComposition composition, float scale,
AnimatableValue.Factory<T> valueFactory) {
PointF cp1 = null;
PointF cp2 = null;
float startFrame = 0;
T startValue = null;
T endValue = null;
Interpolator interpolator = null;
if (json.has("t")) {
startFrame = (float) json.optDouble("t", 0);
Object startValueJson = json.opt("s");
if (startValueJson != null) {
startValue = valueFactory.valueFromObject(startValueJson, scale);
}
Object endValueJson = json.opt("e");
if (endValueJson != null) {
endValue = valueFactory.valueFromObject(endValueJson, scale);
}
JSONObject cp1Json = json.optJSONObject("o");
JSONObject cp2Json = json.optJSONObject("i");
if (cp1Json != null && cp2Json != null) {
cp1 = JsonUtils.pointFromJsonObject(cp1Json, scale);
cp2 = JsonUtils.pointFromJsonObject(cp2Json, scale);
}
boolean hold = json.optInt("h", 0) == 1;
if (hold) {
endValue = startValue;
// TODO: create a HoldInterpolator so progress changes don't invalidate.
interpolator = LINEAR_INTERPOLATOR;
} else if (cp1 != null) {
interpolator = PathInterpolatorCompat.create(
cp1.x / scale, cp1.y / scale, cp2.x / scale, cp2.y / scale);
} else {
interpolator = LINEAR_INTERPOLATOR;
}
} else {
startValue = valueFactory.valueFromObject(json, scale);
endValue = startValue;
}
return new Keyframe<>(composition, startValue, endValue, interpolator, startFrame, null);
}
示例13: KanboardTask
import org.json.JSONObject; //导入方法依赖的package包/类
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"));
}
示例14: Response
import org.json.JSONObject; //导入方法依赖的package包/类
public Response(JSONObject json) {
// status defaults to success
mStatus = new Status();
JSONObject error = json.optJSONObject(Keys.Error);
if (error != null) {
mStatus.setSuccess(false);
mStatus.setErrorMessage(error.optString(Keys.Message, "Unknown Error"));
mStatus.setStatusCode(error.optInt(Keys.Status, 500));
}
// top-level JSON properties
mConversationId = json.optString(Keys.ConversationId);
mParticipantId = json.optString(Keys.ParticipantId);
mETag = json.optString(Keys.ETag);
mAsrHypothesis = json.optString(Keys.AsrHypothesis);
mEndpoint = json.optString(Keys.EndpointHeader);
mTimedResponseInterval = json.optDouble(Keys.TimedResponseInterval, 0);
// last modified
String interval = json.optString(Keys.LastModified);
if (!interval.isEmpty()) {
SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT, Locale.US);
try {
mLastModified = dateFormat.parse(interval);
} catch (ParseException e) {
e.printStackTrace();
mLastModified = null;
}
}
// outputs
mOutputs = new ArrayList<>();
JSONArray outputs = json.optJSONArray(Keys.Outputs);
if (outputs != null) {
for (int i = 0; i < outputs.length(); i++) {
JSONObject output = outputs.optJSONObject(i);
if (output == null || !output.has(Keys.OutputType)) {
continue;
}
String type = output.optString(Keys.OutputType);
if (type.equals(OutputType.BEHAVIOR.toString())) {
mOutputs.add(new BehaviorOutput(output));
} else if (type.equals(OutputType.DIALOG.toString())) {
mOutputs.add(new DialogOutput(output));
}
}
}
// entities -- convert from JSON dictionary to an array
mEntities = new ArrayList<>();
JSONObject entities = json.optJSONObject(Keys.Entities);
if (entities != null) {
Iterator<String> keys = entities.keys();
while (keys.hasNext()) {
String key = keys.next();
Object entity = entities.opt(key);
if (entity == null) {
continue;
}
if (entity instanceof String) {
mEntities.add(new Label(key, (String)entity));
} else if (entity instanceof JSONArray) {
JSONArray arr = (JSONArray) entity;
ArrayList<Object> list = new ArrayList<>();
for (int i = 0; i < arr.length(); i++) {
Object item = arr.opt(i);
if (item != null) list.add(item);
}
mEntities.add(new List(key, list));
} else if (entity instanceof Boolean) {
mEntities.add(new Flag(key, (boolean)entity));
} else if (entity instanceof Number) {
mEntities.add(new Counter(key, ((Number)entity).doubleValue()));
}
}
}
}
示例15: parseNutrition
import org.json.JSONObject; //导入方法依赖的package包/类
private void parseNutrition(JSONObject nutrition) {
String[] keys = new String[]{"carbohydrate,碳水化合物", "fat,脂肪", "protein,蛋白质"};
this.viewDietNuturitions.removeAllViews();
for (String keyValue : keys) {
String key = keyValue.split(",")[0];
String value = keyValue.split(",")[1];
JSONObject item = nutrition.optJSONObject(key);
double weight = item.optDouble("weight");
double percentage = item.optDouble("percentage");
DietShareNutritionItem view = new DietShareNutritionItem(this);
view.setIngredient(value);
try {
String result = String.format("%.1f", new Object[]{Double.valueOf(weight)});
if (result.endsWith(".0")) {
result = result.substring(0, result.indexOf(".0"));
}
view.setShowContent(String.format("%s克", new Object[]{result}));
} catch (Exception e) {
e.printStackTrace();
}
int percent = (int) (100.0d * percentage);
if (percent > 0) {
try {
view.setPercent(percent + "%");
} catch (Exception e2) {
e2.printStackTrace();
return;
}
}
view.setPercent("0%");
try {
String description = item.getString("description");
if (!(TextUtils.isEmpty(description) || description.equals("null"))) {
view.setIndicateTextWithString(description);
}
} catch (JSONException e3) {
e3.printStackTrace();
}
this.viewDietNuturitions.addView(view);
}
}