com.github.openjson.JSONObject.get()方法的使用及代码示例

x33g5p2x  于2022-01-22 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(146)

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

JSONObject.get介绍

[英]Returns the value mapped by name, or throws if no such mapping exists.
[中]返回按名称映射的值,如果不存在此类映射,则抛出。

代码示例

代码示例来源:origin: com.github.openjson/openjson

/**
 * Returns the value mapped by {@code name} if it exists and is a {@code
 * JSONObject}, or throws otherwise.
 *
 * @param name The name of the field that we want.
 * @return a specified field value (if it is a JSONObject)
 * @throws JSONException if the mapping doesn't exist or is not a {@code
 *                       JSONObject}.
 */
public JSONObject getJSONObject(String name) throws JSONException {
  Object object = get(name);
  if (object instanceof JSONObject) {
    return (JSONObject) object;
  } else {
    throw JSON.typeMismatch(name, object, "JSONObject");
  }
}

代码示例来源:origin: org.wicketstuff/wicket-gchart

if (jsonObj.get("properties") instanceof JSONObject) {
  JSONObject props = (JSONObject) jsonObj.get("properties");
  for (String name : JSONObject.getNames(props)) {
    columnDeclaration.getProperties().put(name, props.get(name));

代码示例来源:origin: com.googlecode.wicket-jquery-ui/wicket-kendo-ui

@Override
public SchedulerEvent toObject(JSONObject object, List<ResourceList> lists)
{
  SchedulerEvent event = this.newSchedulerEvent();
  event.setId(object.get("id")); // Object
  event.setTitle(object.optString("title"));
  event.setDescription(object.optString("description"));
  event.setStart(DateUtils.toZonedDateTime(object.getLong("start"), this.offset));
  event.setUntil(DateUtils.toZonedDateTime(object.getLong("end"), this.offset));
  event.setAllDay(object.getBoolean("isAllDay"));
  event.setRecurrenceId(object.optString("recurrenceId"));
  event.setRecurrenceRule(object.optString("recurrenceRule"));
  event.setRecurrenceException(object.optString("recurrenceException"));
  // Resources //
  for (ResourceList list : lists)
  {
    String field = list.getField();
    Object value = object.opt(field);
    if (list.isMultiple() && value instanceof JSONArray)
    {
      event.setValue(field, JsonUtils.toList((JSONArray) value));
    }
    else
    {
      event.setValue(field, value);
    }
  }
  return event;
}

代码示例来源:origin: com.github.openjson/openjson

/**
 * Returns the value mapped by {@code name} if it exists and is a {@code
 * JSONArray}, or throws otherwise.
 *
 * @param name The field we want to get.
 * @return The value of the field (if it is a JSONArray.
 * @throws JSONException if the mapping doesn't exist or is not a {@code
 *                       JSONArray}.
 */
public JSONArray getJSONArray(String name) throws JSONException {
  Object object = get(name);
  if (object instanceof JSONArray) {
    return (JSONArray) object;
  } else {
    throw JSON.typeMismatch(name, object, "JSONArray");
  }
}

代码示例来源:origin: sebfz1/wicket-jquery-ui

@Override
public SchedulerEvent toObject(JSONObject object, List<ResourceList> lists)
{
  SchedulerEvent event = this.newSchedulerEvent();
  event.setId(object.get("id")); // Object
  event.setTitle(object.optString("title"));
  event.setDescription(object.optString("description"));
  event.setStart(DateUtils.toZonedDateTime(object.getLong("start"), this.offset));
  event.setUntil(DateUtils.toZonedDateTime(object.getLong("end"), this.offset));
  event.setAllDay(object.getBoolean("isAllDay"));
  event.setRecurrenceId(object.optString("recurrenceId"));
  event.setRecurrenceRule(object.optString("recurrenceRule"));
  event.setRecurrenceException(object.optString("recurrenceException"));
  // Resources //
  for (ResourceList list : lists)
  {
    String field = list.getField();
    Object value = object.opt(field);
    if (list.isMultiple() && value instanceof JSONArray)
    {
      event.setValue(field, JsonUtils.toList((JSONArray) value));
    }
    else
    {
      event.setValue(field, value);
    }
  }
  return event;
}

代码示例来源:origin: com.github.openjson/openjson

/**
 * Returns the value mapped by {@code name} if it exists and is an int or
 * can be coerced to an int, or throws otherwise.
 *
 * @param name The name of the field we want.
 * @return The selected value if it exists.
 * @throws JSONException if the mapping doesn't exist or cannot be coerced
 *                       to an int.
 */
public int getInt(String name) throws JSONException {
  Object object = get(name);
  Integer result = JSON.toInteger(object);
  if (result == null) {
    throw JSON.typeMismatch(name, object, "int");
  }
  return result;
}

代码示例来源:origin: triplea-game/triplea

/**
  * Converts the properties of the specified JSON object into a map of equivalent Java types. Any {@link JSONArray}
  * property value will be converted into an equivalent {@code List<Object>}; any {@link JSONObject} property value
  * will be converted into an equivalent {@code Map<String, Object>}.
  *
  * @param jsonObject The JSON object.
  *
  * @return A map of the specified JSON object's properties converted to their equivalent Java types. The keys are the
  *         property names; the values are the property values.
  */
 public static Map<String, Object> toMap(final JSONObject jsonObject) {
  checkNotNull(jsonObject);

  final Map<String, Object> map = new HashMap<>(jsonObject.length());
  for (final String name : jsonObject.keySet()) {
   map.put(name, unwrap(jsonObject.get(name)));
  }
  return map;
 }
}

代码示例来源:origin: com.github.openjson/openjson

/**
 * Returns the value mapped by {@code name} if it exists and is a boolean or
 * can be coerced to a boolean, or throws otherwise.
 *
 * @param name The name of the field we want.
 * @return The selected value if it exists.
 * @throws JSONException if the mapping doesn't exist or cannot be coerced
 *                       to a boolean.
 */
public boolean getBoolean(String name) throws JSONException {
  Object object = get(name);
  Boolean result = JSON.toBoolean(object);
  if (result == null) {
    throw JSON.typeMismatch(name, object, "boolean");
  }
  return result;
}

代码示例来源:origin: com.github.openjson/openjson

/**
 * Returns the value mapped by {@code name} if it exists and is a double or
 * can be coerced to a double, or throws otherwise.
 *
 * @param name The name of the field we want.
 * @return The selected value if it exists.
 * @throws JSONException if the mapping doesn't exist or cannot be coerced
 *                       to a double.
 */
public double getDouble(String name) throws JSONException {
  Object object = get(name);
  Double result = JSON.toDouble(object);
  if (result == null) {
    throw JSON.typeMismatch(name, object, "double");
  }
  return result;
}

代码示例来源:origin: com.github.openjson/openjson

/**
 * Returns the value mapped by {@code name} if it exists, coercing it if
 * necessary, or throws if no such mapping exists.
 *
 * @param name The name of the field we want.
 * @return The value of the field.
 * @throws JSONException if no such mapping exists.
 */
public String getString(String name) throws JSONException {
  Object object = get(name);
  String result = JSON.toString(object);
  if (result == null) {
    throw JSON.typeMismatch(name, object, "String");
  }
  return result;
}

代码示例来源:origin: com.github.openjson/openjson

/**
 * Returns the value mapped by {@code name} if it exists and is a long or
 * can be coerced to a long, or throws otherwise.
 * Note that JSON represents numbers as doubles,
 *
 * so this is <a href="#lossy">lossy</a>; use strings to transfer numbers
 * via JSON without loss.
 *
 * @param name The name of the field that we want.
 * @return The value of the field.
 * @throws JSONException if the mapping doesn't exist or cannot be coerced
 *                       to a long.
 */
public long getLong(String name) throws JSONException {
  Object object = get(name);
  Long result = JSON.toLong(object);
  if (result == null) {
    throw JSON.typeMismatch(name, object, "long");
  }
  return result;
}

代码示例来源:origin: org.wicketstuff/wicket-gchart

/**
 * Build instance from a JSONobject.
 *
 * @param json JSON object to build map from. If this contains other
 * JSONObjects nested, a corresponding nested structure of ChartOptions will
 * be built.
 * @return New instance with data from the JSONObject.
 */
public static ChartOptions fromJson(JSONObject json) {
  ChartOptions chartOptions = new ChartOptions();
  for (String key : json.keySet()) {
    Object obj = json.get(key);
    if (obj instanceof JSONObject) {
      chartOptions.put(key, fromJson((JSONObject) obj));
    } else {
      chartOptions.put(key, obj);
    }
  }
  return chartOptions;
}

相关文章