本文整理汇总了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;
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
}
示例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());
}
}
}
示例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));
}
}
示例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;
}
}
示例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();
}
}
示例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);
}
}
示例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));
}
}
}
示例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);
}
}
示例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);
}
}
}
示例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);
}
示例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)));
}
}