org.json.JSONObject.getBigDecimal()方法的使用及代码示例

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

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

JSONObject.getBigDecimal介绍

[英]Get the BigDecimal value associated with a key. If the value is float or double, the the BigDecimal#BigDecimal(double) constructor will be used. See notes on the constructor for conversion issues that may arise.
[中]获取与键关联的BigDecimal值。如果值是float或double,则将使用BigDecimal#BigDecimal(double)构造函数。有关可能出现的转换问题,请参见构造函数上的注释。

代码示例

代码示例来源:origin: org.codeartisans/org.json

/**
 * Get an optional BigDecimal associated with a key, or the defaultValue if
 * there is no such key or if its value is not a number. If the value is a
 * string, an attempt will be made to evaluate it as a number.
 *
 * @param key
 *            A key string.
 * @param defaultValue
 *            The default.
 * @return An object which is the value.
 */
public BigDecimal optBigDecimal(String key, BigDecimal defaultValue) {
  try {
    return this.getBigDecimal(key);
  } catch (Exception e) {
    return defaultValue;
  }
}

代码示例来源:origin: MoriTanosuke/glacieruploader

public String printArchiveSize(final JSONObject archive) throws JSONException {
    final BigDecimal size = archive.getBigDecimal("Size");
    final String humanReadableSize = HumanReadableSize.parse(size);
    return size + " (" + humanReadableSize + ")";
  }
}

代码示例来源:origin: simplesteph/medium-blog-kafka-udemy

public Review jsonToReview(JSONObject reviewJson) {
  Review.Builder reviewBuilder = Review.newBuilder();
  reviewBuilder.setContent(reviewJson.getString("content"));
  reviewBuilder.setId(reviewJson.getLong("id"));
  reviewBuilder.setRating(reviewJson.getBigDecimal("rating").toPlainString());
  reviewBuilder.setTitle(reviewJson.getString("content"));
  reviewBuilder.setCreated(DateTime.parse(reviewJson.getString("created")));
  reviewBuilder.setModified(DateTime.parse(reviewJson.getString("modified")));
  reviewBuilder.setUser(jsonToUser(reviewJson.getJSONObject("user")));
  reviewBuilder.setCourse(jsonToCourse(reviewJson.getJSONObject("course")));
  return reviewBuilder.build();
}

相关文章

JSONObject类方法