org.json.JSONArray.getDouble()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(9.3k)|赞(0)|评价(0)|浏览(152)

本文整理了Java中org.json.JSONArray.getDouble()方法的一些代码示例,展示了JSONArray.getDouble()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONArray.getDouble()方法的具体详情如下:
包路径:org.json.JSONArray
类名称:JSONArray
方法名:getDouble

JSONArray.getDouble介绍

[英]Returns the value at index if it exists and is a double or can be coerced to a double.
[中]返回索引处的值(如果该值存在且为双精度值或可以强制为双精度值)。

代码示例

代码示例来源:origin: zzz40500/GsonFormat

/**
 * Get the optional double value associated with an index. The defaultValue
 * is returned if there is no value for the index, or if the value is not a
 * number and cannot be converted to a number.
 *
 * @param index
 *            subscript
 * @param defaultValue
 *            The default value.
 * @return The value.
 */
public double optDouble(int index, double defaultValue) {
  try {
    return this.getDouble(index);
  } catch (Exception e) {
    return defaultValue;
  }
}

代码示例来源:origin: googlemaps/android-maps-utils

/**
 * Parses an array containing a coordinate into a LatLngAlt object
 *
 * @param coordinates array containing the GeoJSON coordinate
 * @return LatLngAlt object
 * @throws JSONException if coordinate cannot be parsed
 */
private static LatLngAlt parseCoordinate(JSONArray coordinates) throws JSONException {
  // GeoJSON stores coordinates as Lng, Lat so we need to reverse
  LatLng latLng = new LatLng(coordinates.getDouble(1), coordinates.getDouble(0));
  Double altitude = (coordinates.length() < 3) ? null : coordinates.getDouble(2);
  return new LatLngAlt(latLng, altitude);
}

代码示例来源:origin: googlemaps/android-maps-utils

/**
 * Parses a bounding box given as a JSONArray of 4 elements in the order of lowest values for
 * all axes followed by highest values. Axes order of a bounding box follows the axes order of
 * geometries.
 *
 * @param coordinates array of 4 coordinates
 * @return LatLngBounds containing the coordinates of the bounding box
 * @throws JSONException if the bounding box could not be parsed
 */
private static LatLngBounds parseBoundingBox(JSONArray coordinates) throws JSONException {
  // Lowest values for all axes
  LatLng southWestCorner = new LatLng(coordinates.getDouble(1), coordinates.getDouble(0));
  // Highest value for all axes
  LatLng northEastCorner = new LatLng(coordinates.getDouble(3), coordinates.getDouble(2));
  return new LatLngBounds(southWestCorner, northEastCorner);
}

代码示例来源:origin: ankidroid/Anki-Android

private int _delayForGrade(JSONObject conf, int left) {
  left = left % 1000;
  try {
    double delay;
    JSONArray ja = conf.getJSONArray("delays");
    int len = ja.length();
    try {
      delay = ja.getDouble(len - left);
    } catch (JSONException e) {
      if (conf.getJSONArray("delays").length() > 0) {
        delay = conf.getJSONArray("delays").getDouble(0);
      } else {
        // user deleted final step; use dummy value
        delay = 1.0;
      }
    }
    return (int) (delay * 60.0);
  } catch (JSONException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: ankidroid/Anki-Android

private int _leftToday(JSONArray delays, int left, long now) {
  if (now == 0) {
    now = Utils.intNow();
  }
  int ok = 0;
  int offset = Math.min(left, delays.length());
  for (int i = 0; i < offset; i++) {
    try {
      now += (int) (delays.getDouble(delays.length() - offset + i) * 60.0);
    } catch (JSONException e) {
      throw new RuntimeException(e);
    }
    if (now > mDayCutoff) {
      break;
    }
    ok = i;
  }
  return ok + 1;
}

代码示例来源:origin: facebook/facebook-android-sdk

float[] array = new float[jsonArray.length()];
for (int i = 0; i < array.length; i++) {
  array[i] = (float)jsonArray.getDouble(i);
double[] array = new double[jsonArray.length()];
for (int i = 0; i < array.length; i++) {
  array[i] = jsonArray.getDouble(i);

代码示例来源:origin: Justson/AgentWeb

values[currIndex] = argsVals.getDouble(currIndex);

代码示例来源:origin: ankidroid/Anki-Android

/**
 * Return the next interval for CARD, in seconds.
 */
public long nextIvl(Card card, int ease) {
  try {
    if (card.getQueue() == 0 || card.getQueue() == 1 || card.getQueue() == 3) {
      return _nextLrnIvl(card, ease);
    } else if (ease == 1) {
      // lapsed
      JSONObject conf = _lapseConf(card);
      if (conf.getJSONArray("delays").length() > 0) {
        return (long) (conf.getJSONArray("delays").getDouble(0) * 60.0);
      }
      return _nextLapseIvl(card, conf) * 86400L;
    } else {
      // review
      return _nextRevIvl(card, ease) * 86400L;
    }
  } catch (JSONException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: apache/geode

Assert.assertEquals("VerifyPdxInstanceToJson: Double[] type values are not matched",
  testObject.getW_doubleArray()[0],
  jsonObject.getJSONArray(testObject.getW_doubleArrayFN()).getDouble(0), 0);
Assert.assertEquals("VerifyPdxInstanceToJson: String[] type values are not matched",
  testObject.getW_strArray()[2],

代码示例来源:origin: googleapis/google-cloud-java

private void assertArray(List<?> actualValues, JSONArray expectedList) throws Exception {
  assertThat(actualValues.size()).isEqualTo(expectedList.length());
  for (int i = 0; i < actualValues.size(); i++) {
   Object actualValue = actualValues.get(i);
   if (actualValue == null) {
    assertThat(expectedList.isNull(i)).isTrue();
   } else {
    if (actualValue instanceof Boolean) {
     assertThat((Boolean) actualValue).isEqualTo(expectedList.getBoolean(i));
    } else if (actualValue instanceof String) {
     assertThat((String) actualValue).isEqualTo(expectedList.getString(i));
    } else if (actualValue instanceof Long) {
     assertThat((Long) actualValue).isEqualTo(expectedList.getLong(i));
    } else if (actualValue instanceof Double) {
     assertThat((Double) actualValue).isEqualTo(expectedList.getDouble(i));
    } else if (actualValue instanceof ByteArray) {
     assertThat((ByteArray) actualValue)
       .isEqualTo(ByteArray.fromBase64(expectedList.getString(i)));
    } else if (actualValue instanceof Struct) {
     Struct actualStruct = (Struct) actualValue;
     JSONArray expectedFields = expectedList.getJSONArray(i);
     assertRow(actualStruct, expectedFields);
    }
   }
  }
 }
}

代码示例来源:origin: googleapis/google-cloud-java

private void assertRow(Struct actualRow, JSONArray expectedRow) throws Exception {
 assertThat(actualRow.getColumnCount()).isEqualTo(expectedRow.length());
 for (int i = 0; i < expectedRow.length(); i++) {
  switch (actualRow.getColumnType(i).getCode()) {
   case BOOL:
    assertThat(actualRow.getBoolean(i)).isEqualTo(expectedRow.getBoolean(i));
    break;
   case STRING:
    assertThat(actualRow.getString(i)).isEqualTo(expectedRow.getString(i));
    break;
   case INT64:
    assertThat(actualRow.getLong(i)).isEqualTo(expectedRow.getLong(i));
    break;
   case FLOAT64:
    assertThat(actualRow.getDouble(i)).isEqualTo(expectedRow.getDouble(i));
    break;
   case BYTES:
    assertThat(actualRow.getBytes(i))
      .isEqualTo(ByteArray.fromBase64(expectedRow.getString(i)));
    break;
   case ARRAY:
    Type elementType = actualRow.getColumnType(i).getArrayElementType();
    assertArray(getRawList(actualRow, i, elementType), expectedRow.getJSONArray(i));
    break;
   default:
    Assert.fail("Unexpected type code:" + actualRow.getColumnType(i).getCode());
  }
 }
}

代码示例来源:origin: parse-community/Parse-SDK-Android

for (int i = 0; i < array.length(); ++i) {
  JSONArray point = array.getJSONArray(i);
  coordinates.add(new ParseGeoPoint(point.getDouble(0), point.getDouble(1)));

代码示例来源:origin: mobnetic/BitcoinChecker

@Override
protected void parseTickerFromJsonObject(int requestId, JSONObject jsonObject, Ticker ticker, CheckerInfo checkerInfo) throws Exception {
  final JSONObject tickerJsonObject = jsonObject.getJSONObject("ticker");
  ticker.bid = tickerJsonObject.getJSONArray("max_bid").getDouble(0);
  ticker.ask = tickerJsonObject.getJSONArray("min_ask").getDouble(0);
  ticker.vol = tickerJsonObject.getJSONArray("volume").getDouble(0);
  ticker.last = tickerJsonObject.getJSONArray("last_price").getDouble(0);
}

代码示例来源:origin: com.eduworks/ew.common

public static double rootMeanSquared(JSONArray value) throws JSONException
{
  Double result = 0.0;
  for (int i = 0;i < value.length();i++)
    result += value.getDouble(i)*value.getDouble(i);
  return Math.sqrt(result/value.length());
}
public static double average(List<Double> value)

代码示例来源:origin: wiglenet/wigle-wifi-wardriving

/**
 * Parses an array containing a coordinate into a LatLng object
 *
 * @param coordinates array containing the GeoJSON coordinate
 * @return LatLng object
 * @throws JSONException if coordinate cannot be parsed
 */
private static LatLng parseCoordinate(JSONArray coordinates) throws JSONException {
  // GeoJSON stores coordinates as Lng, Lat so we need to reverse
  return new LatLng(coordinates.getDouble(1), coordinates.getDouble(0));
}

代码示例来源:origin: com.eduworks/ew.common

public static Double min(JSONArray objAsJsonArray) throws JSONException
{
  Double result = Double.MAX_VALUE;
  for (int i = 0;i < objAsJsonArray.length();i++)
    result = Math.min(result, objAsJsonArray.getDouble(i));
  return result;
}

代码示例来源:origin: mobnetic/BitcoinChecker

@Override
protected void parseTickerFromJsonObject(int requestId, JSONObject jsonObject, Ticker ticker, CheckerInfo checkerInfo) throws Exception {
  final JSONObject tickerJsonObject = jsonObject.getJSONObject("tick");
  ticker.bid = tickerJsonObject.getJSONArray("bid").getDouble(0);
  ticker.ask = tickerJsonObject.getJSONArray("ask").getDouble(0);
  ticker.vol = tickerJsonObject.getDouble("vol");
  ticker.high = tickerJsonObject.getDouble("high");
  ticker.low = tickerJsonObject.getDouble("low");
  ticker.last = tickerJsonObject.getDouble("close");
}

代码示例来源:origin: stackoverflow.com

// get the array of coordinates buried two levels down of singleton arrays  
   JSONArray array = coord.getJSONArray(0).getJSONArray(0);
   // iterate through the array of coordinates
   for (int i = 0; i < array.length(); i++) {
     JSONArray inside = array.getJSONArray(i);
     for (int j = 0; j < inside.length(); j++) {
       System.out.println(inside.getDouble(j));
     }
   }

代码示例来源:origin: org.apache.giraph/giraph-core

@Override
protected DoubleWritable getValue(JSONArray jsonVertex) throws
 JSONException, IOException {
 return new DoubleWritable(jsonVertex.getDouble(1));
}

代码示例来源:origin: com.eduworks/ew.levr.base

@Override
public Object resolve(Context c, Map<String, String[]> parameters, Map<String, InputStream> dataStreams) throws JSONException
{
  JSONArray array = getObjAsJsonArray(c, parameters, dataStreams);
  Double result = 0.0;
  for (int i = 0;i < array.length();i++)
    result += array.getDouble(i);
  return result;
}

相关文章