當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonElement.getAsDouble方法代碼示例

本文整理匯總了Java中com.google.gson.JsonElement.getAsDouble方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonElement.getAsDouble方法的具體用法?Java JsonElement.getAsDouble怎麽用?Java JsonElement.getAsDouble使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.gson.JsonElement的用法示例。


在下文中一共展示了JsonElement.getAsDouble方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: extractDouble

import com.google.gson.JsonElement; //導入方法依賴的package包/類
public double extractDouble(JsonObject json, String name, int defaultValue) {
    if (json != null) {
        int dotIndex = name.indexOf('.');
        if (dotIndex > 0) {
            String baseName = name.substring(0, dotIndex);
            JsonElement childElement = json.get(baseName);
            return extractDouble((JsonObject) childElement, name.substring(dotIndex + 1), defaultValue);
        }
        JsonElement element = json.get(name);
        if (element != null && ! element.isJsonNull()) {
            return element.getAsDouble();
        }
    }
    return defaultValue;
}
 
開發者ID:Sixt,項目名稱:ja-micro,代碼行數:16,代碼來源:JsonUtil.java

示例2: deserialize

import com.google.gson.JsonElement; //導入方法依賴的package包/類
@Override
public Double deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    try {
        return json.getAsDouble();
    } catch (Exception e) {
        TLog.log("DoubleJsonDeserializer-deserialize-error:" + (json != null ? json.toString() : ""));
        return 0D;
    }
}
 
開發者ID:hsj-xiaokang,項目名稱:OSchina_resources_android,代碼行數:10,代碼來源:DoubleJsonDeserializer.java

示例3: getDouble

import com.google.gson.JsonElement; //導入方法依賴的package包/類
/**
 * 
 * @param path
 * @return
 */
public Double getDouble(String path, Double defaultVal) {
	JsonElement jsonElt = getLastJsonEltInPath(path);

	if (jsonElt == null || jsonElt.isJsonNull()) {
		return defaultVal;
	} else {
		return jsonElt.getAsDouble();
	}
}
 
開發者ID:coffee-to-code,項目名稱:EasyJson,代碼行數:15,代碼來源:EasyJson.java

示例4: deserialize

import com.google.gson.JsonElement; //導入方法依賴的package包/類
@Override
public Double deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    try {
        return json.getAsDouble();
    } catch (Exception e) {
        LogUtils.d("DoubleJsonDeserializer-deserialize-error:" + (json != null ? json.toString() : ""));
        return 0d;
    }
}
 
開發者ID:coding-dream,項目名稱:TPlayer,代碼行數:10,代碼來源:DoubleJsonDeserializer.java

示例5: getValue

import com.google.gson.JsonElement; //導入方法依賴的package包/類
private static <T> T getValue(JsonElement element, T compared) throws IllegalStateException, ClassCastException, IllegalArgumentException {
    if (compared instanceof Double) {
        return (T)(new Double(element.getAsDouble()));
    }
    else if (compared instanceof Integer) {
        return (T)(new Integer(element.getAsInt()));
    }
    else if (compared instanceof JsonObject) {
        return (T)element.getAsJsonObject();
    }
    else if (compared instanceof JsonArray) {
        return (T)element.getAsJsonArray();
    }
    else if (compared instanceof String) {
        return (T)element.getAsString();
    }
    else if (compared instanceof Boolean) {
        return (T)(new Boolean(element.getAsBoolean()));
    }

    throw new IllegalArgumentException();
}
 
開發者ID:stuebz88,項目名稱:modName,代碼行數:23,代碼來源:JsonUtil.java

示例6: getDataPoint

import com.google.gson.JsonElement; //導入方法依賴的package包/類
@Override
public DataPoint getDataPoint(long timestamp, JsonElement json)
{
	double value = 0.0;
	if (!json.isJsonNull())
		value = json.getAsDouble();
	return new DoubleDataPoint(timestamp, value);
}
 
開發者ID:quqiangsheng,項目名稱:abhot,代碼行數:9,代碼來源:DoubleDataPointFactoryImpl.java

示例7: fromJson

import com.google.gson.JsonElement; //導入方法依賴的package包/類
@Override
public Double fromJson(final JsonElement json)
{
    return json.getAsDouble();
}
 
開發者ID:Leviathan-Studio,項目名稱:MineIDE,代碼行數:6,代碼來源:DataTypeList.java

示例8: DoubleValue

import com.google.gson.JsonElement; //導入方法依賴的package包/類
protected DoubleValue(final JsonElement v, final boolean deprecated, final String encryptionProfile)
{
    super(deprecated, encryptionProfile);
    this.value = v.getAsDouble();
}
 
開發者ID:ConfigHubPub,項目名稱:JavaAPI,代碼行數:6,代碼來源:Properties.java

示例9: getAsDouble

import com.google.gson.JsonElement; //導入方法依賴的package包/類
public static Double getAsDouble(JsonElement element) {
  return isNull(element) ? null : element.getAsDouble();
}
 
開發者ID:11590692,項目名稱:Wechat-Group,代碼行數:4,代碼來源:GsonHelper.java

示例10: 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);
	}
}
 
開發者ID:neur0nus,項目名稱:storm-clickhouse,代碼行數:55,代碼來源:JsonJdbcMapper.java


注:本文中的com.google.gson.JsonElement.getAsDouble方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。