当前位置: 首页>>代码示例>>Java>>正文


Java JsonObject.has方法代码示例

本文整理汇总了Java中com.google.gson.JsonObject.has方法的典型用法代码示例。如果您正苦于以下问题:Java JsonObject.has方法的具体用法?Java JsonObject.has怎么用?Java JsonObject.has使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.gson.JsonObject的用法示例。


在下文中一共展示了JsonObject.has方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: toGameProfile

import com.google.gson.JsonObject; //导入方法依赖的package包/类
/**
 * Convert a {@linkplain com.google.gson.JsonObject JsonObject} into a {@linkplain com.mojang.authlib.GameProfile}.
 * The json object must have {@code uuid} and {@code name} attributes or {@code null} will be returned.
 */
private static GameProfile toGameProfile(JsonObject json)
{
    if (json.has("uuid") && json.has("name"))
    {
        String s = json.get("uuid").getAsString();
        UUID uuid;

        try
        {
            uuid = UUID.fromString(s);
        }
        catch (Throwable var4)
        {
            return null;
        }

        return new GameProfile(uuid, json.get("name").getAsString());
    }
    else
    {
        return null;
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:28,代码来源:UserListBansEntry.java

示例2: validateResponse

import com.google.gson.JsonObject; //导入方法依赖的package包/类
/**
 * Validating the network response.
 * @param response {@link LiBaseResponse}
 * @return LiBaseResponse {@link LiBaseResponse}
 * @throws LiRestResponseException
 */
private LiBaseResponse validateResponse(LiBaseResponse response) throws LiRestResponseException {
    String jsonStr = null;
    try {
        jsonStr = asString(response);
    } catch (IOException e) {
        Log.e(LOG_TAG, "Error deserializing json");
        throw LiRestResponseException.jsonSerializationError("Error deserializing rest response");
    }
    Gson gson = getGson();
    JsonObject jsonObject = gson.fromJson(jsonStr, JsonObject.class);
    if (jsonObject.has("http_code")) {
        int httpResponeCode = jsonObject.get("http_code").getAsInt();
        if (httpResponeCode == 200 || httpResponeCode == 201) {
            response.setData(jsonObject);
            return response;
        } else {
            Log.e(LOG_TAG, "Error response from server");
            throw LiRestResponseException.fromJson(jsonObject.getAsString(), gson);
        }
    } else {
        Log.e(LOG_TAG, "Error response from server");
        throw LiRestResponseException.fromJson(jsonObject.getAsString(), gson);
    }
}
 
开发者ID:lithiumtech,项目名称:li-android-sdk-core,代码行数:31,代码来源:LiRestv2Client.java

示例3: parseMapVariants

import com.google.gson.JsonObject; //导入方法依赖的package包/类
protected Map<String, VariantList> parseMapVariants(JsonDeserializationContext deserializationContext, JsonObject object)
{
    Map<String, VariantList> map = Maps.<String, VariantList>newHashMap();

    if (object.has("variants"))
    {
        JsonObject jsonobject = JsonUtils.getJsonObject(object, "variants");

        for (Entry<String, JsonElement> entry : jsonobject.entrySet())
        {
            map.put(entry.getKey(), (VariantList)deserializationContext.deserialize((JsonElement)entry.getValue(), VariantList.class));
        }
    }

    return map;
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:17,代码来源:ModelBlockDefinition.java

示例4: getTextures

import com.google.gson.JsonObject; //导入方法依赖的package包/类
private Map<String, String> getTextures(JsonObject p_178329_1_)
{
    Map<String, String> map = Maps.<String, String>newHashMap();

    if (p_178329_1_.has("textures"))
    {
        JsonObject jsonobject = p_178329_1_.getAsJsonObject("textures");

        for (Entry<String, JsonElement> entry : jsonobject.entrySet())
        {
            map.put(entry.getKey(), ((JsonElement)entry.getValue()).getAsString());
        }
    }

    return map;
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:17,代码来源:ModelBlock.java

示例5: gameProfileFromJsonObject

import com.google.gson.JsonObject; //导入方法依赖的package包/类
private static GameProfile gameProfileFromJsonObject(JsonObject p_152646_0_)
{
    if (p_152646_0_.has("uuid") && p_152646_0_.has("name"))
    {
        String s = p_152646_0_.get("uuid").getAsString();
        UUID uuid;

        try
        {
            uuid = UUID.fromString(s);
        }
        catch (Throwable var4)
        {
            return null;
        }

        return new GameProfile(uuid, p_152646_0_.get("name").getAsString());
    }
    else
    {
        return null;
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:24,代码来源:UserListWhitelistEntry.java

示例6: checkError

import com.google.gson.JsonObject; //导入方法依赖的package包/类
private void checkError(JsonObject data) {
    if (data.has("error")) {
        LogUtil.e(TAG, "extract error: " + data.toString());
        JsonObject jsonObject = data.getAsJsonObject("error");
        String errorMsg = jsonObject.get("note").getAsString();
        // TODO: 1/25/17 Try to avoid hard-coding
        if (errorMsg.contains("该视频已经加密")) {
            throw new ExtractException("Youku said: Sorry, this video is private");
        } else if (errorMsg.contains("抱歉,该视频仅限中国大陆地区播放,请您观看其他视频!")) {
            throw new ExtractException("Youku said: Sorry, this video is available in China only");
        } else {
            throw new ExtractException("Youku server reported error " + jsonObject.get("error").getAsString());
        }
    }

}
 
开发者ID:TedaLIEz,项目名称:ParsingPlayer,代码行数:17,代码来源:YoukuExtractor.java

示例7: templateFromJSon

import com.google.gson.JsonObject; //导入方法依赖的package包/类
public TemplateField templateFromJSon( JsonElement json, JsonDeserializationContext context ) {
	if (!json.isJsonObject()) {
		throw new JsonParseException("Unexpected JsonElement!");
	}
	JsonObject jo = (JsonObject) json;
	if ((!jo.has(jSonUtils.FORMAL_ID)) || (!jo.has(jSonUtils.VALUE_ID))) {
		throw new JsonParseException("Required attributes are not available!");
	}
	boolean isFormal = jo.get(FORMAL_ID).getAsBoolean();
	if (isFormal) {
		try {
			return new FormalField(dicionary.getClass(jo.get(VALUE_ID).getAsString()));
		} catch (ClassNotFoundException e) {
			throw new JsonParseException(e);
		}
	} else {
		return new ActualField(objectFromJson(jo.get(VALUE_ID), context));
	}
}
 
开发者ID:pSpaces,项目名称:jSpace,代码行数:20,代码来源:jSonUtils.java

示例8: func_152643_b

import com.google.gson.JsonObject; //导入方法依赖的package包/类
private static GameProfile func_152643_b(JsonObject p_152643_0_)
{
    if (p_152643_0_.has("uuid") && p_152643_0_.has("name"))
    {
        String s = p_152643_0_.get("uuid").getAsString();
        UUID uuid;

        try
        {
            uuid = UUID.fromString(s);
        }
        catch (Throwable var4)
        {
            return null;
        }

        return new GameProfile(uuid, p_152643_0_.get("name").getAsString());
    }
    else
    {
        return null;
    }
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:24,代码来源:UserListOpsEntry.java

示例9: readTempData

import com.google.gson.JsonObject; //导入方法依赖的package包/类
private void readTempData(File file) {
	try (FileReader reader = new FileReader(tempDataFile)) {
		JsonObject root = GSON.fromJson(reader, JsonObject.class);
		if (root == null) return;
		
		for (Entry<String, JsonElement> entry : root.entrySet()) {
			World world = Bukkit.getWorld(entry.getKey());
			if (world == null) return;
			
			EndWorldWrapper wrapper = dedManager.getWorldWrapper(world);
			JsonObject element = entry.getValue().getAsJsonObject();
			
			if (element.has("respawnTime")) {
				if (wrapper.isRespawnInProgress()) wrapper.stopRespawn();
				
				wrapper.startRespawn(element.get("respawnTime").getAsInt());
			}
			
			Collection<EnderDragon> dragons = world.getEntitiesByClass(EnderDragon.class);
			if (element.has("activeTemplate") && !dragons.isEmpty()) {
				DragonTemplate template = dedManager.getTemplate(element.get("activeTemplate").getAsString());
				if (template == null) return;
				
				wrapper.setActiveBattle(template);
				template.applyToBattle(nmsAbstract, Iterables.get(dragons, 0), nmsAbstract.getEnderDragonBattleFromWorld(world));
			}
		}
	} catch (IOException | JsonParseException e) {
		e.printStackTrace();
	}
}
 
开发者ID:2008Choco,项目名称:DragonEggDrop,代码行数:32,代码来源:DragonEggDrop.java

示例10: BinanceExchangeStats

import com.google.gson.JsonObject; //导入方法依赖的package包/类
public BinanceExchangeStats(JsonObject response) throws BinanceApiException {
    if (!response.has("data")) {
        throw new BinanceApiException("Missing restrictions in response object while trying to get restrictions");
    }
    JsonArray pairs = response.get("data").getAsJsonArray();
    products.clear();
    for (JsonElement entry: pairs) {
        BinanceExchangeProduct symbol = new BinanceExchangeProduct(entry.getAsJsonObject());
        products.add(symbol);
    }
}
 
开发者ID:webcerebrium,项目名称:java-binance-api,代码行数:12,代码来源:BinanceExchangeStats.java

示例11: parseMetadataSection

import com.google.gson.JsonObject; //导入方法依赖的package包/类
public <T extends IMetadataSection> T parseMetadataSection(String p_110503_1_, JsonObject p_110503_2_)
{
    if (p_110503_1_ == null)
    {
        throw new IllegalArgumentException("Metadata section name cannot be null");
    }
    else if (!p_110503_2_.has(p_110503_1_))
    {
        return (T)null;
    }
    else if (!p_110503_2_.get(p_110503_1_).isJsonObject())
    {
        throw new IllegalArgumentException("Invalid metadata for \'" + p_110503_1_ + "\' - expected object, found " + p_110503_2_.get(p_110503_1_));
    }
    else
    {
        IMetadataSerializer.Registration<?> registration = (IMetadataSerializer.Registration)this.metadataSectionSerializerRegistry.getObject(p_110503_1_);

        if (registration == null)
        {
            throw new IllegalArgumentException("Don\'t know how to handle metadata section \'" + p_110503_1_ + "\'");
        }
        else
        {
            return (T)((IMetadataSection)this.getGson().fromJson((JsonElement)p_110503_2_.getAsJsonObject(p_110503_1_), registration.field_110500_b));
        }
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:29,代码来源:IMetadataSerializer.java

示例12: deserializeClass

import com.google.gson.JsonObject; //导入方法依赖的package包/类
public static <T> T deserializeClass(JsonObject json, String memberName, JsonDeserializationContext context, Class <? extends T > adapter)
{
    if (json.has(memberName))
    {
        return deserializeClass(json.get(memberName), memberName, context, adapter);
    }
    else
    {
        throw new JsonSyntaxException("Missing " + memberName);
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:12,代码来源:JsonUtils.java

示例13: merge

import com.google.gson.JsonObject; //导入方法依赖的package包/类
private void merge(JsonObject source, JsonObject dest) {
  for (Map.Entry<String, JsonElement> entry: source.entrySet()) {
    JsonArray values = entry.getValue().getAsJsonArray();
    if (dest.has(entry.getKey())) {
      dest.get(entry.getKey()).getAsJsonArray().addAll(values);
    } else {
      dest.add(entry.getKey(), values);
    }
  }
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:11,代码来源:DataCheck.java

示例14: optStringArray

import com.google.gson.JsonObject; //导入方法依赖的package包/类
protected static String[] optStringArray(JsonObject root, String name, String[] fallback){
    if(!root.has(name)){
        return fallback;
    }

    JsonArray array = root.getAsJsonArray(name);
    return parseStringArray(array);
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:9,代码来源:AbsAdapter.java

示例15: getOrAndCondition

import com.google.gson.JsonObject; //导入方法依赖的package包/类
@VisibleForTesting
static ICondition getOrAndCondition(JsonObject json)
{
    Set<Entry<String, JsonElement>> set = json.entrySet();

    if (set.isEmpty())
    {
        throw new JsonParseException("No elements found in selector");
    }
    else
    {
        return (ICondition)(set.size() == 1 ? (json.has("OR") ? new ConditionOr(Iterables.transform(JsonUtils.getJsonArray(json, "OR"), FUNCTION_OR_AND)) : (json.has("AND") ? new ConditionAnd(Iterables.transform(JsonUtils.getJsonArray(json, "AND"), FUNCTION_OR_AND)) : makePropertyValue((Entry)set.iterator().next()))) : new ConditionAnd(Iterables.transform(set, FUNCTION_PROPERTY_VALUE)));
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:15,代码来源:Selector.java


注:本文中的com.google.gson.JsonObject.has方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。