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


Java JsonElement.isJsonObject方法代码示例

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


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

示例1: fromJson

import com.google.gson.JsonElement; //导入方法依赖的package包/类
@Override
public void fromJson(final JsonElement json)
{
    if (!json.isJsonObject())
        throw new IllegalArgumentException("json is not an object");

    JsonObject all = json.getAsJsonObject();

    String type = all.get("content-type").getAsString();
    JsonElement data = all.get("data");

    if (type.equals(this.contentType))
    {
        this.dataFromJson(data);
    }
}
 
开发者ID:Leviathan-Studio,项目名称:MineIDE,代码行数:17,代码来源:BaseContent.java

示例2: update

import com.google.gson.JsonElement; //导入方法依赖的package包/类
/**
 * Method to update config.
 * @param file file to store the updated config
 * @param data date to write to the config
 * @return boolean
 */
public boolean update(final File file, final Object data) {
    JsonElement old = JsonUtils.convertObjectToJsonTree(GSON, this);
    JsonElement updates = JsonUtils.convertObjectToJsonTree(GSON, data);

    boolean success = true;
    if (!old.isJsonObject() && !updates.isJsonObject()) {
        LOGGER.warning(String.format("Could not update the config at %s as it or the updated data is not an object.", file.getName()));
        success = false;
    } else {
        JsonObject oldObj = old.getAsJsonObject();
        JsonObject updatesObj = updates.getAsJsonObject();

        update(oldObj, updatesObj);

        try (FileWriter fw = new FileWriter(file)) {
            String jsonStr = JsonUtils.convertObjectToJson(GSON, oldObj);
            fw.write(jsonStr);
            fw.close();
        } catch (IOException e) {
            LOGGER.warning(String.format("Could not save the updated config to %s.", file.getName()));
            success = false;
        }
    }
    return success;
}
 
开发者ID:enjin,项目名称:Enjin-Coin-Java-SDK,代码行数:32,代码来源:JsonConfig.java

示例3: parseAnimationFrame

import com.google.gson.JsonElement; //导入方法依赖的package包/类
private AnimationFrame parseAnimationFrame(int frame, JsonElement element)
{
    if (element.isJsonPrimitive())
    {
        return new AnimationFrame(JsonUtils.getInt(element, "frames[" + frame + "]"));
    }
    else if (element.isJsonObject())
    {
        JsonObject jsonobject = JsonUtils.getJsonObject(element, "frames[" + frame + "]");
        int i = JsonUtils.getInt(jsonobject, "time", -1);

        if (jsonobject.has("time"))
        {
            Validate.inclusiveBetween(1L, 2147483647L, (long)i, "Invalid frame time");
        }

        int j = JsonUtils.getInt(jsonobject, "index");
        Validate.inclusiveBetween(0L, 2147483647L, (long)j, "Invalid frame index");
        return new AnimationFrame(j, i);
    }
    else
    {
        return null;
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:26,代码来源:AnimationMetadataSectionSerializer.java

示例4: parseAccountDataEvents

import com.google.gson.JsonElement; //导入方法依赖的package包/类
private void parseAccountDataEvents(JsonObject syncData) {
	if(syncData.has("account_data") &&
	   syncData.get("account_data").isJsonObject()) {
		JsonObject accountDataObject = syncData.get("account_data").getAsJsonObject();

		if(accountDataObject.has("events") &&
		   accountDataObject.get("events").isJsonArray()) {
			JsonArray accountDataEvents = accountDataObject.get("events").getAsJsonArray();

			for(JsonElement eventElement : accountDataEvents) {
				if(eventElement.isJsonObject()) {
					JsonObject event = eventElement.getAsJsonObject();

					parseAccountDataEvent(event);
				}
			}
		}
	}
}
 
开发者ID:Gurgy,项目名称:Cypher,代码行数:20,代码来源:Client.java

示例5: encodeCanonicalElement

import com.google.gson.JsonElement; //导入方法依赖的package包/类
private static void encodeCanonicalElement(JsonElement el, JsonWriterUnchecked writer) {
    try {
        if (el.isJsonObject()) encodeCanonical(el.getAsJsonObject(), writer);
        else if (el.isJsonPrimitive()) writer.jsonValue(el.toString());
        else if (el.isJsonArray()) encodeCanonicalArray(el.getAsJsonArray(), writer);
        else if (el.isJsonNull()) writer.nullValue();
        else throw new JsonCanonicalException("Unexpected JSON type, this is a bug, report!");
    } catch (IOException e) {
        throw new JsonCanonicalException(e);
    }
}
 
开发者ID:kamax-io,项目名称:matrix-java-sdk,代码行数:12,代码来源:MatrixJson.java

示例6: serialize

import com.google.gson.JsonElement; //导入方法依赖的package包/类
@Override
public JsonElement serialize(Holder src, Type type, JsonSerializationContext context) {
  JsonObject root = new JsonObject();
  JsonElement value = context.serialize(src.value());

  root.addProperty("id", src.id());

  if (value.isJsonObject()) {
    value.getAsJsonObject().addProperty(Holder.TYPE_PROPERTY, src.value().getClass().getName());
  }

  root.add(VALUE_PROPERTY, value);
  return root;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:HolderJsonSerializer.java

示例7: deserialize

import com.google.gson.JsonElement; //导入方法依赖的package包/类
public UserListEntry<K> deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
    if (p_deserialize_1_.isJsonObject())
    {
        JsonObject jsonobject = p_deserialize_1_.getAsJsonObject();
        UserListEntry<K> userlistentry = UserList.this.createEntry(jsonobject);
        return userlistentry;
    }
    else
    {
        return null;
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:14,代码来源:UserList.java

示例8: loadAccount

import com.google.gson.JsonElement; //导入方法依赖的package包/类
public Data loadAccount(String address)
{
    try (FileReader reader = new FileReader(this.conf))
    {
        JsonElement jsonObject = this.gson.fromJson(reader, JsonElement.class);
        if (jsonObject != null && jsonObject.isJsonObject() && jsonObject.getAsJsonObject().has(address))
        {
            JsonObject account = jsonObject.getAsJsonObject().getAsJsonObject(address);
            String userid = account.has("user") ? account.get("user").getAsString() : "";
            if (account.has("name") && account.has("uuid") && account.has("auth"))
            {
                String name = account.get("name").getAsString();
                String uuid = account.get("uuid").getAsString();
                String accessToken = account.get("auth").getAsString();
                return new Data(userid, name, uuid, accessToken);
            }
            else
            {
                return new Data(userid);
            }
        }
        else
        {
            return new Data("", "", "", "");
        }
    }
    catch (IOException e)
    {
        String path = this.conf.getAbsolutePath();
        this.logger.info("AuthlibLoginHelper: Find error when loading account to " + path, e);
        return new Data("", "", "", "");
    }
}
 
开发者ID:ustc-zzzz,项目名称:AuthlibLoginHelper,代码行数:34,代码来源:AuthlibLoginHelper.java

示例9: getMap

import com.google.gson.JsonElement; //导入方法依赖的package包/类
@Override
public <K, T, M extends Map<K, T>> void getMap(String key, Class<K> keyType, Class<T> type, M map)
{
    JsonElement element = this.getElement(this.element, key);
    if ((element == null) || ! element.isJsonObject())
    {
        throw new DeserializationException(type, this, "Can't find valid value for key: " + key);
    }

    JsonObject jsonObject = element.getAsJsonObject();
    for (Entry<String, JsonElement> entry : jsonObject.entrySet())
    {
        K keyObj;
        if (Serialization.isSimpleType(keyType))
        {
            keyObj = this.context.deserialize(new JsonPrimitive(entry.getKey()), keyType);
        }
        else if (this.serialization.isStringSerializable(keyType))
        {
            keyObj = this.serialization.deserializeFromString(keyType, entry.getKey());
        }
        else
        {
            throw new DeserializationException(type, this, "Can't deserialize given string to key: (" + type.getName() + ") -> " + entry.getKey());
        }

        map.put(keyObj, this.context.deserialize(entry.getValue(), type));
    }
}
 
开发者ID:GotoFinal,项目名称:diorite-configs-java8,代码行数:30,代码来源:JsonDeserializationData.java

示例10: write

import com.google.gson.JsonElement; //导入方法依赖的package包/类
public void write(JsonWriter out, JsonElement value) throws IOException {
    if (value == null || value.isJsonNull()) {
        out.nullValue();
    } else if (value.isJsonPrimitive()) {
        JsonPrimitive primitive = value.getAsJsonPrimitive();
        if (primitive.isNumber()) {
            out.value(primitive.getAsNumber());
        } else if (primitive.isBoolean()) {
            out.value(primitive.getAsBoolean());
        } else {
            out.value(primitive.getAsString());
        }
    } else if (value.isJsonArray()) {
        out.beginArray();
        Iterator it = value.getAsJsonArray().iterator();
        while (it.hasNext()) {
            write(out, (JsonElement) it.next());
        }
        out.endArray();
    } else if (value.isJsonObject()) {
        out.beginObject();
        for (Entry<String, JsonElement> e : value.getAsJsonObject().entrySet()) {
            out.name((String) e.getKey());
            write(out, (JsonElement) e.getValue());
        }
        out.endObject();
    } else {
        throw new IllegalArgumentException("Couldn't write " + value.getClass());
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:31,代码来源:TypeAdapters.java

示例11: write

import com.google.gson.JsonElement; //导入方法依赖的package包/类
public void write(JsonWriter out, JsonElement value) throws IOException {
    if (value == null || value.isJsonNull()) {
        out.nullValue();
    } else if (value.isJsonPrimitive()) {
        JsonPrimitive primitive = value.getAsJsonPrimitive();
        if (primitive.isNumber()) {
            out.value(primitive.getAsNumber());
        } else if (primitive.isBoolean()) {
            out.value(primitive.getAsBoolean());
        } else {
            out.value(primitive.getAsString());
        }
    } else if (value.isJsonArray()) {
        out.beginArray();
        i$ = value.getAsJsonArray().iterator();
        while (i$.hasNext()) {
            write(out, (JsonElement) i$.next());
        }
        out.endArray();
    } else if (value.isJsonObject()) {
        out.beginObject();
        for (Entry<String, JsonElement> e : value.getAsJsonObject().entrySet()) {
            out.name((String) e.getKey());
            write(out, (JsonElement) e.getValue());
        }
        out.endObject();
    } else {
        throw new IllegalArgumentException("Couldn't write " + value.getClass());
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:31,代码来源:TypeAdapters.java

示例12: databeanFromJson

import com.google.gson.JsonElement; //导入方法依赖的package包/类
private static <PK extends PrimaryKey<PK>,D extends Databean<PK,D>>
D databeanFromJson(Supplier<D> databeanSupplier, DatabeanFielder<PK,D> fielder, JsonObject json, boolean flatKey){
	if(json == null){
		return null;
	}
	D databean = databeanSupplier.get();
	JsonObject pkJson;
	if(flatKey){
		pkJson = json;
	}else{
		pkJson = json.getAsJsonObject(databean.getKeyFieldName());
	}
	primaryKeyFromJson(databean.getKey(), fielder.getKeyFielder(), pkJson);
	List<Field<?>> fields = fielder.getNonKeyFields(databean);
	for(Field<?> field : fields){
		String jsonFieldName = field.getKey().getColumnName();
		JsonElement jsonValue = json.get(jsonFieldName);
		if(jsonValue == null || jsonValue.isJsonNull()){// careful: only skip nulls, not empty strings
			continue;
		}
		String valueString;
		if(jsonValue.isJsonObject()){
			valueString = jsonValue.toString();
		}else{
			valueString = jsonValue.getAsString();
		}
		Object value = field.parseStringEncodedValueButDoNotSet(valueString);
		field.setUsingReflection(databean, value);
	}
	return databean;
}
 
开发者ID:hotpads,项目名称:datarouter,代码行数:32,代码来源:JsonDatabeanTool.java

示例13: parseEvents

import com.google.gson.JsonElement; //导入方法依赖的package包/类
private void parseEvents(JsonObject timeline) {
	if (timeline.has("events") &&
	    timeline.get("events").isJsonArray()) {
		JsonArray events = timeline.get("events").getAsJsonArray();
		for (JsonElement eventElement : events) {
			if (eventElement.isJsonObject()) {
				parseEventData(eventElement.getAsJsonObject());
			}
		}
	}
}
 
开发者ID:Gurgy,项目名称:Cypher,代码行数:12,代码来源:Room.java

示例14: toString

import com.google.gson.JsonElement; //导入方法依赖的package包/类
/**
 * Gets a human-readable description of the given JsonElement's type.  For example: "a number (4)"
 */
public static String toString(JsonElement p_151222_0_)
{
    String s = org.apache.commons.lang3.StringUtils.abbreviateMiddle(String.valueOf((Object)p_151222_0_), "...", 10);

    if (p_151222_0_ == null)
    {
        return "null (missing)";
    }
    else if (p_151222_0_.isJsonNull())
    {
        return "null (json)";
    }
    else if (p_151222_0_.isJsonArray())
    {
        return "an array (" + s + ")";
    }
    else if (p_151222_0_.isJsonObject())
    {
        return "an object (" + s + ")";
    }
    else
    {
        if (p_151222_0_.isJsonPrimitive())
        {
            JsonPrimitive jsonprimitive = p_151222_0_.getAsJsonPrimitive();

            if (jsonprimitive.isNumber())
            {
                return "a number (" + s + ")";
            }

            if (jsonprimitive.isBoolean())
            {
                return "a boolean (" + s + ")";
            }
        }

        return s;
    }
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:44,代码来源:JsonUtils.java

示例15: jsonAsObject

import com.google.gson.JsonElement; //导入方法依赖的package包/类
protected JsonObject jsonAsObject(JsonElement element, String field) throws SchemaViolationError {
    if (!element.isJsonObject()) {
        throw new SchemaViolationError(this, field, element);
    }
    return element.getAsJsonObject();
}
 
开发者ID:Shopify,项目名称:graphql_java_gen,代码行数:7,代码来源:AbstractResponse.java


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