本文整理汇总了Java中org.json.JSONArray.optDouble方法的典型用法代码示例。如果您正苦于以下问题:Java JSONArray.optDouble方法的具体用法?Java JSONArray.optDouble怎么用?Java JSONArray.optDouble使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.json.JSONArray
的用法示例。
在下文中一共展示了JSONArray.optDouble方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: valueFromObject
import org.json.JSONArray; //导入方法依赖的package包/类
@Override public Integer valueFromObject(Object object, float scale) {
JSONArray colorArray = (JSONArray) object;
if (colorArray.length() == 4) {
boolean shouldUse255 = true;
for (int i = 0; i < colorArray.length(); i++) {
double colorChannel = colorArray.optDouble(i);
if (colorChannel > 1f) {
shouldUse255 = false;
}
}
float multiplier = shouldUse255 ? 255f : 1f;
return Color.argb(
(int) (colorArray.optDouble(3) * multiplier),
(int) (colorArray.optDouble(0) * multiplier),
(int) (colorArray.optDouble(1) * multiplier),
(int) (colorArray.optDouble(2) * multiplier));
}
return Color.BLACK;
}
示例2: parseWith
import org.json.JSONArray; //导入方法依赖的package包/类
@Override
public void parseWith(JSONObject data) {
super.parseWith(data);
if (data != null) {
column = data.optInt(KEY_COLUMN, 0);
autoExpand = data.optBoolean(KEY_AUTO_EXPAND, false);
JSONArray jsonCols = data.optJSONArray(KEY_COLS);
if (jsonCols != null) {
cols = new float[jsonCols.length()];
for (int i = 0; i < cols.length; i++) {
cols[i] = (float) jsonCols.optDouble(i, 0);
}
} else {
cols = new float[0];
}
hGap = Style.dp2px(data.optDouble(KEY_H_GAP, 0.0f));
vGap = Style.dp2px(data.optDouble(KEY_V_GAP, 0.0f));
}
}
示例3: parseWith
import org.json.JSONArray; //导入方法依赖的package包/类
@Override
public void parseWith(JSONObject data) {
super.parseWith(data);
if (data != null) {
JSONArray jsonCols = data.optJSONArray(KEY_COLS);
if (jsonCols != null) {
cols = new float[jsonCols.length()];
for (int i = 0; i < cols.length; i++) {
cols[i] = (float) jsonCols.optDouble(i, 0);
}
} else {
cols = new float[0];
}
JSONArray jsonRows = data.optJSONArray(KEY_ROWS);
if (jsonRows != null) {
rows = new float[jsonRows.length()];
for (int i = 0; i < rows.length; i++) {
rows[i] = (float) jsonRows.optDouble(i, 0);
}
} else {
rows = new float[0];
}
}
}
示例4: pointFromJsonArray
import org.json.JSONArray; //导入方法依赖的package包/类
static PointF pointFromJsonArray(JSONArray values, float scale) {
if (values.length() < 2) {
throw new IllegalArgumentException("Unable to parse point for " + values);
}
return new PointF(
(float) values.optDouble(0, 1) * scale,
(float) values.optDouble(1, 1) * scale);
}
示例5: getFloatArray
import org.json.JSONArray; //导入方法依赖的package包/类
public float[] getFloatArray(String key) {
try {
JSONArray array = data.getJSONArray(key);
int length = array.length();
float[] result = new float[length];
for (int i = 0; i < length; i++) {
result[i] = (float) array.optDouble(i, 0.0);
}
return result;
} catch (JSONException e) {
reportException(e);
return null;
}
}
示例6: parse
import org.json.JSONArray; //导入方法依赖的package包/类
public static GeoOri parse(JSONObject object) {
GeoOri geoOri = null;
if (object != null) {
geoOri = new GeoOri();
geoOri.type = object.optString("type");
JSONArray array = object.optJSONArray("coordinates");
geoOri.latitude = array.optDouble(0);
geoOri.longitude = array.optDouble(1);
}
return geoOri;
}
示例7: valueFromObject
import org.json.JSONArray; //导入方法依赖的package包/类
@Override public ScaleXY valueFromObject(Object object, float scale) {
JSONArray array = (JSONArray) object;
return new ScaleXY(
(float) array.optDouble(0, 1) / 100f * scale,
(float) array.optDouble(1, 1) / 100f * scale);
}