本文整理了Java中com.google.gson.JsonElement.getAsObject()
方法的一些代码示例,展示了JsonElement.getAsObject()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonElement.getAsObject()
方法的具体详情如下:
包路径:com.google.gson.JsonElement
类名称:JsonElement
方法名:getAsObject
[英]convenience method to get this element as an Object value.
[中]获取此元素作为对象值的方便方法。
代码示例来源:origin: stackoverflow.com
for (JsonElement je2 : array)
Set<Map.Entry<String,JsonElement>> set = je2.getAsObject().entrySet();
JsonElement je3 = set.iterator().next().getValue();
mp.results = je.getAsObject().getAsJsonPrimitive("results").getAsInt();
代码示例来源:origin: eatnumber1/google-gson
/**
* convenience method to get this array as an Object if it contains a single element.
*
* @return get this element as an Object if it is single element array.
* @throws ClassCastException if the element in the array is of not a {@link JsonPrimitive} and
* is not a valid Object.
* @throws IllegalStateException if the array has more than one element.
*/
@Override
Object getAsObject() {
if (elements.size() == 1) {
return elements.get(0).getAsObject();
}
throw new IllegalStateException();
}
代码示例来源:origin: stackoverflow.com
class ChildDeserializer implements JsonDeserializer<CategoryModel>
{
@Override
public ChildHolder deserialize(JsonElement json, Type typeOfT,
JsonDeserializationContext context)
throws JsonParseException {
JsonObject obj = json.getAsObject();
JsonElement e = obj.get("child");
if (e.isJsonPrimitive()) // it's a String
{
obj.remove("child");
obj.add("child", new JsonArray());
}
return new Gson().fromJson(obj, CategoryModel.class);
}
}
内容来源于网络,如有侵权,请联系作者删除!