当前位置: 首页>>代码示例>>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;未经允许,请勿转载。