本文整理了Java中com.google.gson.JsonElement.getAsNumber()
方法的一些代码示例,展示了JsonElement.getAsNumber()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonElement.getAsNumber()
方法的具体详情如下:
包路径:com.google.gson.JsonElement
类名称:JsonElement
方法名:getAsNumber
[英]convenience method to get this element as a Number.
[中]以数字形式获取此元素的方便方法。
代码示例来源:origin: searchbox-io/Jest
return (T) id.getAsNumber();
代码示例来源:origin: MovingBlocks/Terasology
name != null ? JsonTreeValue.Type.KEY_VALUE_PAIR : JsonTreeValue.Type.VALUE));
} else if (primitive.isNumber()) {
return new JsonTree(new JsonTreeValue(name, json.getAsNumber(),
name != null ? JsonTreeValue.Type.KEY_VALUE_PAIR : JsonTreeValue.Type.VALUE));
} else if (primitive.isString()) {
代码示例来源:origin: jamesagnew/hapi-fhir
@Override
public Number getAsNumber() {
return nativeValue != null ? nativeValue.getAsNumber() : null;
}
代码示例来源:origin: camunda/camunda-bpm-platform
/**
* convenience method to get this array as a {@link Number} if it contains a single element.
*
* @return get this element as a number if it is single element array.
* @throws ClassCastException if the element in the array is of not a {@link JsonPrimitive} and
* is not a valid Number.
* @throws IllegalStateException if the array has more than one element.
*/
@Override
public Number getAsNumber() {
if (elements.size() == 1) {
return elements.get(0).getAsNumber();
}
throw new IllegalStateException();
}
代码示例来源:origin: Mojang/DataFixerUpper
@Override
public Optional<Number> getNumberValue(final JsonElement input) {
if (input.isJsonPrimitive() && input.getAsJsonPrimitive().isNumber()) {
return Optional.of(input.getAsNumber());
}
return Optional.empty();
}
代码示例来源:origin: jamesagnew/hapi-fhir
@Override
public Object getValue() {
if (nativeValue != null && nativeValue.isJsonPrimitive()) {
if (((JsonPrimitive)nativeValue).isNumber()) {
return nativeValue.getAsNumber();
}
if (((JsonPrimitive)nativeValue).isBoolean()) {
return Boolean.valueOf(nativeValue.getAsBoolean());
}
return nativeValue.getAsString();
}
return null;
}
代码示例来源:origin: ca.uhn.hapi.fhir/hapi-fhir-base
@Override
public Number getAsNumber() {
return nativeValue != null ? nativeValue.getAsNumber() : null;
}
代码示例来源:origin: lucko/helper
@Nonnull
@Override
public Number asNumber() {
return this.element.getAsNumber();
}
代码示例来源:origin: me.lucko/helper
@Nonnull
@Override
public Number asNumber() {
return this.element.getAsNumber();
}
代码示例来源:origin: Bkm016/TabooLib
/**
* 获取成员
*
* @param index 序号
* @param def 默认值
* @return number
*/
public Number getNumber(int index, Number def) {
return jsonArray.get(index).isJsonPrimitive() ? jsonArray.get(index).getAsNumber() : def;
}
代码示例来源:origin: MCMrARM/revolution-irc
public static Object spanFromJson(JsonObject obj) {
String type = obj.get("type").getAsString();
if (type.equals(SPAN_TYPE_FOREGROUND))
return new ForegroundColorSpan(obj.get("color").getAsNumber().intValue());
if (type.equals(SPAN_TYPE_BACKGROUND))
return new BackgroundColorSpan(obj.get("color").getAsNumber().intValue());
if (type.equals(SPAN_TYPE_STYLE))
return new StyleSpan(obj.get("style").getAsNumber().intValue());
return null;
}
代码示例来源:origin: com.mapbox.mapboxsdk/mapbox-java-geojson
/**
* Convenience method to get a Number member.
*
* @param key name of the member
* @return the value of the member, null if it doesn't exist
* @since 1.0.0
*/
public Number getNumberProperty(String key) {
return getProperties().get(key).getAsNumber();
}
代码示例来源:origin: Bkm016/TabooLib
/**
* 获取数字
*
* @param path 地址
* @param def 默认值
* @return Number
*/
public Number getNumber(String path, Number def) {
JsonElement jsonElement = get(path);
return !(jsonElement instanceof JsonPrimitive) || jsonElement == null ? def : jsonElement.getAsNumber();
}
代码示例来源:origin: mapbox/mapbox-java
/**
* Convenience method to get a Number member.
*
* @param key name of the member
* @return the value of the member, null if it doesn't exist
* @since 1.0.0
*/
public Number getNumberProperty(String key) {
return properties().get(key).getAsNumber();
}
代码示例来源:origin: com.mapbox.mapboxsdk/mapbox-sdk-geojson
/**
* Convenience method to get a Number member.
*
* @param key name of the member
* @return the value of the member, null if it doesn't exist
* @since 1.0.0
*/
public Number getNumberProperty(String key) {
return properties().get(key).getAsNumber();
}
代码示例来源:origin: google/graphicsfuzz
public List<Number> getArgs(String name) {
final List<Number> result = new ArrayList<>();
final JsonArray args = lookupUniform(name).get("args")
.getAsJsonArray();
for (int i = 0; i < args.size(); i++) {
result.add(args.get(i).getAsNumber());
}
return result;
}
代码示例来源:origin: burtcorp/jmespath-java
@Override
public Number toNumber(JsonElement value) {
return (value.isJsonPrimitive() && value.getAsJsonPrimitive().isNumber()) ? value.getAsNumber() : null;
}
代码示例来源:origin: com.ibm.messaging/watson-iot
/**
* Updates the value of this resource with the given Json value
*/
@Override
public int update(JsonElement json, boolean fireEvent) {
this.setValue(json.getAsNumber(), fireEvent);
return this.getRC();
}
代码示例来源:origin: ibm-watson-iot/iot-java
/**
* Updates the value of this resource with the given Json value
*/
@Override
public int update(JsonElement json, boolean fireEvent) {
this.setValue(json.getAsNumber(), fireEvent);
return this.getRC();
}
代码示例来源:origin: eatnumber1/google-gson
public Number deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {
try {
return json.getAsNumber();
} catch (NumberFormatException e) {
throw new JsonSyntaxException(e);
} catch (UnsupportedOperationException e) {
throw new JsonSyntaxException(e);
} catch (IllegalStateException e) {
throw new JsonSyntaxException(e);
}
}
内容来源于网络,如有侵权,请联系作者删除!