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

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

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

JSONArray.isEmpty介绍

[英]Check if JSONArray is empty.
[中]检查JSONArray是否为空。

代码示例

代码示例来源:origin: b3log/latke

/**
 * Produce a JSONObject by combining a JSONArray of names with the values of
 * this JSONArray.
 *
 * @param names
 *            A JSONArray containing a list of key strings. These will be
 *            paired with the values.
 * @return A JSONObject, or null if there are no names or if this JSONArray
 *         has no values.
 * @throws JSONException
 *             If any of the names are null.
 */
public JSONObject toJSONObject(JSONArray names) throws JSONException {
  if (names == null || names.isEmpty() || this.isEmpty()) {
    return null;
  }
  JSONObject jo = new JSONObject(names.length());
  for (int i = 0; i < names.length(); i += 1) {
    jo.put(names.getString(i), this.opt(i));
  }
  return jo;
}

代码示例来源:origin: b3log/latke

/**
 * Produce a JSONArray containing the values of the members of this
 * JSONObject.
 *
 * @param names
 *            A JSONArray containing a list of key strings. This determines
 *            the sequence of the values in the result.
 * @return A JSONArray of values.
 * @throws JSONException
 *             If any of the values are non-finite numbers.
 */
public JSONArray toJSONArray(JSONArray names) throws JSONException {
  if (names == null || names.isEmpty()) {
    return null;
  }
  JSONArray ja = new JSONArray();
  for (int i = 0; i < names.length(); i += 1) {
    ja.put(this.opt(names.getString(i)));
  }
  return ja;
}

代码示例来源:origin: org.b3log/latke

/**
 * Produce a JSONObject by combining a JSONArray of names with the values of
 * this JSONArray.
 *
 * @param names
 *            A JSONArray containing a list of key strings. These will be
 *            paired with the values.
 * @return A JSONObject, or null if there are no names or if this JSONArray
 *         has no values.
 * @throws JSONException
 *             If any of the names are null.
 */
public JSONObject toJSONObject(JSONArray names) throws JSONException {
  if (names == null || names.isEmpty() || this.isEmpty()) {
    return null;
  }
  JSONObject jo = new JSONObject(names.length());
  for (int i = 0; i < names.length(); i += 1) {
    jo.put(names.getString(i), this.opt(i));
  }
  return jo;
}

代码示例来源:origin: org.b3log/latke

/**
 * Produce a JSONArray containing the values of the members of this
 * JSONObject.
 *
 * @param names
 *            A JSONArray containing a list of key strings. This determines
 *            the sequence of the values in the result.
 * @return A JSONArray of values.
 * @throws JSONException
 *             If any of the values are non-finite numbers.
 */
public JSONArray toJSONArray(JSONArray names) throws JSONException {
  if (names == null || names.isEmpty()) {
    return null;
  }
  JSONArray ja = new JSONArray();
  for (int i = 0; i < names.length(); i += 1) {
    ja.put(this.opt(names.getString(i)));
  }
  return ja;
}

代码示例来源:origin: jnidzwetzki/bitfinex-v2-wss-api-java

/**
 * {@inheritDoc}
 */
@Override
public void handleChannelData(final String action, final JSONArray payload) throws BitfinexClientException {
  logger.debug("Got notification callback {}", payload.toString());
  if (payload.isEmpty()) {
    return;
  }
  // Test for order error callback
  // [0,"n",[null,"on-req",null,null,[null,null,1513970684865000,"tBTCUSD",null,null,0.001,0.001,"EXCHANGE MARKET",null,null,null,null,null,null,null,12940,null,null,null,null,null,null,0,null,null],null,"ERROR","Invalid order: minimum size for BTC/USD is 0.002"]]
  if ("on-req".equals(payload.getString(1))) {
    final String state = payload.optString(6);
    if ("ERROR".equals(state)) {
      BitfinexSubmittedOrder exchangeOrder = jsonToBitfinexSubmittedOrder(payload);
      submittedOrderConsumer.accept(symbol, exchangeOrder);
    }
  }
}

代码示例来源:origin: jnidzwetzki/bitfinex-v2-wss-api-java

/**
 * {@inheritDoc}
 */
@Override
public void handleChannelData(final String action, final JSONArray payload) throws BitfinexClientException {
  logger.info("Got order callback {}", payload.toString());
  // No orders active
  if (payload.isEmpty()) {
    eventConsumer.accept(symbol, Lists.newArrayList());
    return;
  }
  // Snapshot or update
  List<BitfinexSubmittedOrder> orders = Lists.newArrayList();
  if (payload.get(0) instanceof JSONArray) {
    for (int orderPos = 0; orderPos < payload.length(); orderPos++) {
      final JSONArray orderArray = payload.getJSONArray(orderPos);
      BitfinexSubmittedOrder exchangeOrder = jsonToBitfinexSubmittedOrder(orderArray);
      orders.add(exchangeOrder);
    }
  } else {
    BitfinexSubmittedOrder exchangeOrder = jsonToBitfinexSubmittedOrder(payload);
    orders.add(exchangeOrder);
  }
  eventConsumer.accept(symbol, orders);
}

代码示例来源:origin: jnidzwetzki/bitfinex-v2-wss-api-java

/**
 * {@inheritDoc}
 */
@Override
public void handleChannelData(final String action, final JSONArray payload) throws BitfinexClientException {
  logger.info("Got position callback {}", payload.toString());
  ArrayList<BitfinexPosition> positions = Lists.newArrayList();
  // No positions active
  if (payload.isEmpty()) {
    positionConsumer.accept(symbol, positions);
    return;
  }
  if (payload.get(0) instanceof JSONArray) {
    // snapshot
    for (int orderPos = 0; orderPos < payload.length(); orderPos++) {
      final JSONArray orderArray = payload.getJSONArray(orderPos);
      BitfinexPosition position = jsonArrayToPosition(orderArray);
      positions.add(position);
    }
  } else {
    // update
    BitfinexPosition position = jsonArrayToPosition(payload);
    positions.add(position);
  }
  positionConsumer.accept(symbol, positions);
}

代码示例来源:origin: jnidzwetzki/bitfinex-v2-wss-api-java

/**
 * {@inheritDoc}
 */
@Override
public void handleChannelData(final String action, final JSONArray payload) throws BitfinexClientException {
  if (payload.isEmpty()) {
    return;
  }
  // channel symbol trade:1m:tLTCUSD
  final Set<BitfinexCandle> candlestickList = new TreeSet<>(Comparator.comparing(BitfinexCandle::getTimestamp));
  // Snapshots contain multiple Bars, Updates only one
  if (payload.get(0) instanceof JSONArray) {
    for (int pos = 0; pos < payload.length(); pos++) {
      final JSONArray parts = payload.getJSONArray(pos);
      BitfinexCandle candlestick = jsonToCandlestick(parts);
      candlestickList.add(candlestick);
    }
  } else {
    BitfinexCandle candlestick = jsonToCandlestick(payload);
    candlestickList.add(candlestick);
  }
  candlesConsumer.accept(symbol, candlestickList);
}

代码示例来源:origin: jnidzwetzki/bitfinex-v2-wss-api-java

/**
 * {@inheritDoc}
 */
@Override
public void handleChannelData(final String action, final JSONArray payload) throws BitfinexClientException {
  List<BitfinexWallet> wallets = Lists.newArrayList();
  if (payload.isEmpty()) {
    walletConsumer.accept(symbol, wallets);
    return;
  }
  if (payload.get(0) instanceof JSONArray) {
    // snapshot
    for (int walletPos = 0; walletPos < payload.length(); walletPos++) {
      final JSONArray walletArray = payload.getJSONArray(walletPos);
      BitfinexWallet wallet = jsonArrayToWallet(walletArray);
      wallets.add(wallet);
    }
  } else {
    // update
    BitfinexWallet wallet = jsonArrayToWallet(payload);
    wallets.add(wallet);
  }
  walletConsumer.accept(symbol, wallets);
}

代码示例来源:origin: fbacchella/jrds

if (uptimePointer != null) {
  v = protectedRead(ctx, uptimePointer);
  if (v == null || v.isEmpty()) {
    return 0;
} else if (startPointer != null) {
  v = protectedRead(ctx, startPointer);
  if (v == null || v.isEmpty()) {
    return 0;
  if (v == null || v.isEmpty()) {
    return 0;

代码示例来源:origin: fbacchella/jrds

@Override
protected Map<String, Number> parseStream(InputStream stream) {
  Configuration c = find(JsonpProvider.class).getConfiguration();
  DocumentContext ctx = JsonPath.parse(stream, c);
  setUptime(findUptime(ctx));
  Map<String, Number> vars = new HashMap<>(collectKeys.size());
  for (Map.Entry<JsonPath, String> e: collectKeys.entrySet()) {
    try {
      JSONArray v = protectedRead(ctx, e.getKey());
      if (v.isEmpty()) {
        log(Level.ERROR, "Failed to collect data '%s': not found", e.getValue());
        break;
      }
      vars.put(e.getValue(), valueToNum(v.get(0)));
    } catch (PathNotFoundException ex) {
      log(Level.ERROR, "Failed to collect data '%s': not found", e.getValue());
    } catch (JSONException ex) {
      log(Level.ERROR, "Failed to collect data '%s': %s", e.getValue(), ex.getMessage());
    }
  }
  return vars;
}

代码示例来源:origin: no.ssb.lds/linked-data-store-persistence-provider-api

} else if (object instanceof JSONArray) {
  JSONArray array = (JSONArray) object;
  if (array.isEmpty()) {
    String path = parentPath.stream().collect(Collectors.joining("."));
    leafNodesByPath.put(path, new FlattenedDocumentLeafNode(documentKey, path, FragmentType.EMPTY_ARRAY, null, fragmentCapacity));

相关文章