本文整理汇总了Java中com.google.gson.JsonElement.getAsFloat方法的典型用法代码示例。如果您正苦于以下问题:Java JsonElement.getAsFloat方法的具体用法?Java JsonElement.getAsFloat怎么用?Java JsonElement.getAsFloat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.gson.JsonElement
的用法示例。
在下文中一共展示了JsonElement.getAsFloat方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFloat
import com.google.gson.JsonElement; //导入方法依赖的package包/类
/**
* Gets the float value of the given JsonElement. Expects the second parameter to be the name of the element's
* field if an error message needs to be thrown.
*/
public static float getFloat(JsonElement p_151220_0_, String p_151220_1_)
{
if (p_151220_0_.isJsonPrimitive() && p_151220_0_.getAsJsonPrimitive().isNumber())
{
return p_151220_0_.getAsFloat();
}
else
{
throw new JsonSyntaxException("Expected " + p_151220_1_ + " to be a Float, was " + toString(p_151220_0_));
}
}
示例2: deserialize
import com.google.gson.JsonElement; //导入方法依赖的package包/类
@Override
public Float deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
try {
return json.getAsFloat();
} catch (Exception e) {
TLog.log("FloatJsonDeserializer-deserialize-error:" + (json != null ? json.toString() : ""));
return 0F;
}
}
示例3: getFloat
import com.google.gson.JsonElement; //导入方法依赖的package包/类
/**
*
* @param path
* @return
*/
public Float getFloat(String path, Float defaultVal) {
JsonElement jsonElt = getLastJsonEltInPath(path);
if (jsonElt == null || jsonElt.isJsonNull()) {
return defaultVal;
} else {
return jsonElt.getAsFloat();
}
}
示例4: deserialize
import com.google.gson.JsonElement; //导入方法依赖的package包/类
@Override
public Float deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
try {
return json.getAsFloat();
} catch (Exception e) {
LogUtils.d("FloatJsonDeserializer-deserialize-error:" + (json != null ? json.toString() : ""));
return 0f;
}
}
示例5: getFloat
import com.google.gson.JsonElement; //导入方法依赖的package包/类
/**
* Gets the float value of the given JsonElement. Expects the second parameter to be the name of the element's
* field if an error message needs to be thrown.
*/
public static float getFloat(JsonElement json, String memberName)
{
if (json.isJsonPrimitive() && json.getAsJsonPrimitive().isNumber())
{
return json.getAsFloat();
}
else
{
throw new JsonSyntaxException("Expected " + memberName + " to be a Float, was " + toString(json));
}
}
示例6: fromJson
import com.google.gson.JsonElement; //导入方法依赖的package包/类
@Override
public Float fromJson(final JsonElement json)
{
return json.getAsFloat();
}
示例7: FloatValue
import com.google.gson.JsonElement; //导入方法依赖的package包/类
protected FloatValue(final JsonElement v, final boolean deprecated, final String encryptionProfile)
{
super(deprecated, encryptionProfile);
this.value = v.getAsFloat();
}
示例8: getAsFloat
import com.google.gson.JsonElement; //导入方法依赖的package包/类
public static Float getAsFloat(JsonElement element) {
return isNull(element) ? null : element.getAsFloat();
}
示例9: getColumns
import com.google.gson.JsonElement; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public List<Column> getColumns(ITuple input) {
try {
String jsonString = input.getString(0);
JsonObject jsonObject = parser.parse(jsonString).getAsJsonObject();
List<Column> columns = new ArrayList<Column>();
for(Column column : schemaColumns) {
String columnName = column.getColumnName();
JsonElement elem = jsonObject.get(columnName);
if (elem==null) continue;
Integer columnSqlType = column.getSqlType();
switch (columnSqlType) {
case Types.VARCHAR:
String strValue = elem.getAsString();
columns.add(new Column(columnName, strValue, columnSqlType));
break;
case Types.FLOAT:
Float floatValue = elem.getAsFloat();
columns.add(new Column(columnName, floatValue, columnSqlType));
break;
case Types.DOUBLE:
Double doubleValue = elem.getAsDouble();
columns.add(new Column(columnName, doubleValue, columnSqlType));
break;
case Types.DATE:
Date dateValue = new Date(FMT_DATE.parseDateTime(elem.getAsString()).toDate().getTime());
columns.add(new Column(columnName, dateValue, columnSqlType));
break;
case Types.TIMESTAMP:
Timestamp timeValue = new Timestamp(elem.getAsLong());
columns.add(new Column(columnName, timeValue, columnSqlType));
break;
case Types.SMALLINT:
Short shortValue = elem.getAsShort();
columns.add(new Column(columnName, shortValue, columnSqlType));
break;
case Types.INTEGER:
Integer intValue = elem.getAsInt();
columns.add(new Column(columnName, intValue, columnSqlType));
break;
case Types.BIGINT:
Long longValue = elem.getAsLong();
columns.add(new Column(columnName, longValue, columnSqlType));
break;
default:
throw new RuntimeException("Unsupported java type in tuple " + Util.getJavaType(columnSqlType));
}
}
return columns;
} catch(Exception err) {
throw new RuntimeException("JSON parsing error", err);
}
}
示例10: getFloat
import com.google.gson.JsonElement; //导入方法依赖的package包/类
public static float getFloat(JsonObject p_getFloat_0_, String p_getFloat_1_, float p_getFloat_2_)
{
JsonElement jsonelement = p_getFloat_0_.get(p_getFloat_1_);
return jsonelement == null ? p_getFloat_2_ : jsonelement.getAsFloat();
}