當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。