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


Java JsonElement.getAsBoolean方法代碼示例

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


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

示例1: deserialize

import com.google.gson.JsonElement; //導入方法依賴的package包/類
public Object deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
		throws JsonParseException {
	if (json.isJsonObject()) {
		JsonObject obj = json.getAsJsonObject();
		try {
			typeOfT = Class.forName(obj.get("class").getAsString());
		} catch (ClassNotFoundException e) {
			throw new JsonParseException(e);
		}
		JsonElement prim = obj.get("primitive");
		if (null != prim && prim.getAsBoolean()) {
			json = obj.get("value");
		}
	} /*
		 * else TODO errore durante il cast da Object[] to T[] if
		 * (json.isJsonArray()) { JsonParser parser = new JsonParser();
		 * JsonArray array =json.getAsJsonArray(); Object[] arr = new
		 * Object[array.size()]; for(int i = 0; i < array.size(); i++) {
		 * arr[i] = context.deserialize(array.get(i),
		 * array.get(i).getClass()); } return arr; }
		 */
	return gson.fromJson(json, typeOfT);
}
 
開發者ID:sap-nocops,項目名稱:Jerkoff,代碼行數:24,代碼來源:ObjectDeserializer.java

示例2: getBoolean

import com.google.gson.JsonElement; //導入方法依賴的package包/類
/**
 * Gets the boolean 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 boolean getBoolean(JsonElement p_151216_0_, String p_151216_1_)
{
    if (p_151216_0_.isJsonPrimitive())
    {
        return p_151216_0_.getAsBoolean();
    }
    else
    {
        throw new JsonSyntaxException("Expected " + p_151216_1_ + " to be a Boolean, was " + toString(p_151216_0_));
    }
}
 
開發者ID:Notoh,項目名稱:DecompiledMinecraft,代碼行數:16,代碼來源:JsonUtils.java

示例3: getBoolean

import com.google.gson.JsonElement; //導入方法依賴的package包/類
/**
 * Gets the boolean 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 boolean getBoolean(JsonElement json, String memberName)
{
    if (json.isJsonPrimitive())
    {
        return json.getAsBoolean();
    }
    else
    {
        throw new JsonSyntaxException("Expected " + memberName + " to be a Boolean, was " + toString(json));
    }
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:16,代碼來源:JsonUtils.java

示例4: deserialize

import com.google.gson.JsonElement; //導入方法依賴的package包/類
@Override
public ArtRef.Autogen deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
  if (json.getAsBoolean()) {
    return ArtRef.Autogen.TRUE;
  }
  return ArtRef.Autogen.FALSE;
}
 
開發者ID:FelixGail,項目名稱:gplaymusic,代碼行數:8,代碼來源:AutogenEnumDeserializer.java

示例5: deserialize

import com.google.gson.JsonElement; //導入方法依賴的package包/類
@Override
public Integer deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
	try {
		return json.getAsInt();
	} catch (NumberFormatException e) {
		return (json.getAsBoolean()) ? 1 : 0;
	}
}
 
開發者ID:xhsun,項目名稱:gw2wrapper,代碼行數:9,代碼來源:BooleanAdapter.java

示例6: completeResponse

import com.google.gson.JsonElement; //導入方法依賴的package包/類
/**
 * Complete a response.
 *
 * @param surveyId   the survey id of the survey you want to complete the response
 * @param responseId the response id of the response you want to complete
 * @param date       the date where the response will be completed (submitdate)
 * @return true if the response was successfuly completed
 * @throws LimesurveyRCException the limesurvey rc exception
 */
public boolean completeResponse(int surveyId, int responseId, LocalDateTime date) throws LimesurveyRCException {
    Map<String, String> responseData = new HashMap<>();
    responseData.put("submitdate", date.format(DateTimeFormatter.ISO_LOCAL_DATE) + " " + date.format(DateTimeFormatter.ISO_LOCAL_TIME));
    JsonElement result = updateResponse(surveyId, responseId, responseData);

    if (!result.getAsBoolean()) {
        throw new LimesurveyRCException(result.getAsString());
    }

    return true;
}
 
開發者ID:Falydoor,項目名稱:limesurvey-rc,代碼行數:21,代碼來源:LimesurveyRC.java

示例7: getBoolean

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

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

示例8: 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

示例9: fromJson

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

示例10: BooleanValue

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

示例11: getAsBoolean

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

示例12: getBoolean

import com.google.gson.JsonElement; //導入方法依賴的package包/類
public static boolean getBoolean(JsonObject p_getBoolean_0_, String p_getBoolean_1_, boolean p_getBoolean_2_)
{
    JsonElement jsonelement = p_getBoolean_0_.get(p_getBoolean_1_);
    return jsonelement == null ? p_getBoolean_2_ : jsonelement.getAsBoolean();
}
 
開發者ID:SkidJava,項目名稱:BaseClient,代碼行數:6,代碼來源:Json.java

示例13: isEnabled

import com.google.gson.JsonElement; //導入方法依賴的package包/類
private static boolean isEnabled(JsonElement node) {
    JsonElement disabled = node.getAsJsonObject().get("disabled");
    return (disabled == null || !disabled.getAsBoolean());
}
 
開發者ID:beyondeye,項目名稱:kjsonpatch,代碼行數:5,代碼來源:PatchTestCase.java

示例14: getBooleanOrDefaultValue

import com.google.gson.JsonElement; //導入方法依賴的package包/類
static Boolean getBooleanOrDefaultValue(JsonElement jsonElement, Boolean defaultValue)
{
    return jsonElement != null ? jsonElement.getAsBoolean() : defaultValue;
}
 
開發者ID:riversun,項目名稱:slacklet,代碼行數:5,代碼來源:GsonHelper.java

示例15: ifNullFalse

import com.google.gson.JsonElement; //導入方法依賴的package包/類
static Boolean ifNullFalse(JsonElement jsonElement)
{
    return jsonElement != null && !jsonElement.isJsonNull() ? jsonElement.getAsBoolean() : false;
}
 
開發者ID:riversun,項目名稱:slacklet,代碼行數:5,代碼來源:GsonHelper.java


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