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


Java JsonElement.getAsInt方法代码示例

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


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

示例1: Error

import com.google.gson.JsonElement; //导入方法依赖的package包/类
public Error(JsonObject fields) {
    JsonElement message = fields.get("message");
    if (message != null && message.isJsonPrimitive() && message.getAsJsonPrimitive().isString()) {
        this.message = message.getAsString();
    } else {
        this.message = "Unknown error";
    }

    JsonElement line = fields.get("line");
    if (line != null && line.isJsonPrimitive() && line.getAsJsonPrimitive().isNumber()) {
        this.line = line.getAsInt();
    } else {
        this.line = 0;
    }

    JsonElement column = fields.get("column");
    if (column != null && column.isJsonPrimitive() && column.getAsJsonPrimitive().isNumber()) {
        this.column = column.getAsInt();
    } else {
        this.column = 0;
    }
}
 
开发者ID:Shopify,项目名称:graphql_java_gen,代码行数:23,代码来源:Error.java

示例2: load

import com.google.gson.JsonElement; //导入方法依赖的package包/类
@Override
public void load(Match match) {
    if (match.getMapContainer().getMapInfo().getJsonObject().has("points")) {
        JsonObject pointsJson = match.getMapContainer().getMapInfo().getJsonObject().get("points").getAsJsonObject();
        JsonElement targetElement = pointsJson.get("target");
        if (targetElement.isJsonPrimitive()) {
            int target = targetElement.getAsInt();
            for (MatchTeam matchTeam : TGM.get().getModule(TeamManagerModule.class).getTeams()) {
                if (!matchTeam.isSpectator()) {
                    targets.put(matchTeam, target);
                }
            }
        } else {
            //todo: per team target parsing
        }
    }
}
 
开发者ID:WarzoneMC,项目名称:Warzone,代码行数:18,代码来源:PointsModule.java

示例3: testGetAllDocs

import com.google.gson.JsonElement; //导入方法依赖的package包/类
@Test
public void testGetAllDocs() {
    createCollection();
    insertDocInDB();
    insertDocInDB();

    RestHeartClientResponse response = api.getAllDocumentsFromCollection(dbName, collName);
    Assert.assertNotNull("Response is null", response);

    JsonObject responseObject = response.getResponseObject();
    Assert.assertNotNull("Json object response is null", responseObject);

    JsonElement returned = responseObject.get("_returned");
    int numberOfElements = returned.getAsInt();
    Assert.assertEquals("response size not as expected", 2, numberOfElements);

    LOGGER.info(GsonUtils.toJson(response.getResponseObject()));
}
 
开发者ID:SoftGorilla,项目名称:restheart-java-client,代码行数:19,代码来源:RestHeartBasicClientApiTest.java

示例4: getInt

import com.google.gson.JsonElement; //导入方法依赖的package包/类
/**
 * Gets the integer value of the given JsonElement.  Expects the second parameter to be the name of the element's
 * field if an error message needs to be thrown.
 */
public static int getInt(JsonElement p_151215_0_, String p_151215_1_)
{
    if (p_151215_0_.isJsonPrimitive() && p_151215_0_.getAsJsonPrimitive().isNumber())
    {
        return p_151215_0_.getAsInt();
    }
    else
    {
        throw new JsonSyntaxException("Expected " + p_151215_1_ + " to be a Int, was " + toString(p_151215_0_));
    }
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:16,代码来源:JsonUtils.java

示例5: getInt

import com.google.gson.JsonElement; //导入方法依赖的package包/类
/**
 * Gets the integer value of the given JsonElement.  Expects the second parameter to be the name of the element's
 * field if an error message needs to be thrown.
 */
public static int getInt(JsonElement json, String memberName)
{
    if (json.isJsonPrimitive() && json.getAsJsonPrimitive().isNumber())
    {
        return json.getAsInt();
    }
    else
    {
        throw new JsonSyntaxException("Expected " + memberName + " to be a Int, was " + toString(json));
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:16,代码来源:JsonUtils.java

示例6: deserialize

import com.google.gson.JsonElement; //导入方法依赖的package包/类
@Override
public CustomCommentsResponse deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonObject root = json.getAsJsonObject();

    CustomCommentsResponse response = new CustomCommentsResponse();

    if (root.has("main")) {
        JsonElement main = root.get("main");
        if (!main.isJsonPrimitive()) {
            response.main = context.deserialize(main, CustomCommentsResponse.Main.class);
        } // "main": false (if has execute errors)
    }

    if (root.has("first_id")) {
        JsonElement firstIdJson = root.get("first_id");
        response.firstId = firstIdJson.isJsonNull() ? null : firstIdJson.getAsInt();
    }

    if (root.has("last_id")) {
        JsonElement lastIdJson = root.get("last_id");
        response.lastId = lastIdJson.isJsonNull() ? null : lastIdJson.getAsInt();
    }

    if (root.has("admin_level")) {
        JsonElement adminLevelJson = root.get("admin_level");
        response.admin_level = adminLevelJson.isJsonNull() ? null : adminLevelJson.getAsInt();
    }

    return response;
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:31,代码来源:CustomCommentsResponseAdapter.java

示例7: getInt

import com.google.gson.JsonElement; //导入方法依赖的package包/类
protected int getInt(String field, int failover) {
    if (!obj.has(field)) {
        return failover;
    }

    JsonElement el = obj.get(field);
    if (el.isJsonNull()) {
        return failover;
    }

    return el.getAsInt();
}
 
开发者ID:kamax-io,项目名称:matrix-java-sdk,代码行数:13,代码来源:MatrixJsonObject.java

示例8: extractInteger

import com.google.gson.JsonElement; //导入方法依赖的package包/类
public int extractInteger(JsonObject json, String name, int defaultValue) {
    if (json != null) {
        int dotIndex = name.indexOf('.');
        if (dotIndex > 0) {
            String baseName = name.substring(0, dotIndex);
            JsonElement childElement = json.get(baseName);
            return extractInteger((JsonObject) childElement, name.substring(dotIndex + 1), defaultValue);
        }
        JsonElement element = json.get(name);
        if (element != null && ! element.isJsonNull()) {
            return element.getAsInt();
        }
    }
    return defaultValue;
}
 
开发者ID:Sixt,项目名称:ja-micro,代码行数:16,代码来源:JsonUtil.java

示例9: deserialize

import com.google.gson.JsonElement; //导入方法依赖的package包/类
@Override
public Integer deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    try {
        return json.getAsInt();
    } catch (Exception e) {
        TLog.log("IntegerJsonDeserializer-deserialize-error:" + (json != null ? json.toString() : ""));
        return 0;
    }
}
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:10,代码来源:IntegerJsonDeserializer.java

示例10: getInteger

import com.google.gson.JsonElement; //导入方法依赖的package包/类
/**
 * 
 * @param path
 * @return
 */
public Integer getInteger(String path, Integer defaultVal) {
	JsonElement jsonElt = getLastJsonEltInPath(path);

	if (jsonElt == null || jsonElt.isJsonNull()) {
		return defaultVal;
	} else {
		return jsonElt.getAsInt();
	}
}
 
开发者ID:coffee-to-code,项目名称:EasyJson,代码行数:15,代码来源:EasyJson.java

示例11: getValue

import com.google.gson.JsonElement; //导入方法依赖的package包/类
private static <T> T getValue(JsonElement element, T compared) throws IllegalStateException, ClassCastException, IllegalArgumentException {
    if (compared instanceof Double) {
        return (T)(new Double(element.getAsDouble()));
    }
    else if (compared instanceof Integer) {
        return (T)(new Integer(element.getAsInt()));
    }
    else if (compared instanceof JsonObject) {
        return (T)element.getAsJsonObject();
    }
    else if (compared instanceof JsonArray) {
        return (T)element.getAsJsonArray();
    }
    else if (compared instanceof String) {
        return (T)element.getAsString();
    }
    else if (compared instanceof Boolean) {
        return (T)(new Boolean(element.getAsBoolean()));
    }

    throw new IllegalArgumentException();
}
 
开发者ID:stuebz88,项目名称:modName,代码行数:23,代码来源:JsonUtil.java

示例12: getInt

import com.google.gson.JsonElement; //导入方法依赖的package包/类
public int getInt(String elementName) {
    JsonElement element = jsonObject.get(elementName);
    return element.getAsInt();
}
 
开发者ID:BenjaminSutter,项目名称:genera,代码行数:5,代码来源:RitualRecipe.java

示例13: jsonMemberToInt

import com.google.gson.JsonElement; //导入方法依赖的package包/类
private static int jsonMemberToInt(JsonElement jsonElement, String memberName) {
    JsonElement jsonMemberElement = jsonElement.getAsJsonObject().get(memberName);
    return jsonMemberElement != null ? jsonMemberElement.getAsInt() : 0;
}
 
开发者ID:teodorakostova,项目名称:BookWorldClient,代码行数:5,代码来源:BookResultsManager.java

示例14: deserialize

import com.google.gson.JsonElement; //导入方法依赖的package包/类
@Override
public VKApiVideo deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonObject root = json.getAsJsonObject();
    VKApiVideo dto = new VKApiVideo();

    dto.id = optInt(root, "id");
    dto.owner_id = optInt(root, "owner_id");
    dto.title = optString(root, "title");
    dto.description = optString(root, "description");
    dto.duration = optInt(root, "duration");
    dto.link = optString(root, "link");
    dto.date = optLong(root, "date");
    dto.adding_date = optLong(root, "adding_date");
    dto.views = optInt(root, "views");

    JsonElement commentJson = root.get("comments");
    if(nonNull(commentJson)){
        if(commentJson.isJsonObject()){
            //for example, newsfeed.getComment
            dto.comments = context.deserialize(commentJson, CommentsDto.class);
        } else {
            // video.get
            dto.comments = new CommentsDto();
            dto.comments.count = commentJson.getAsInt();
        }
    }

    dto.player = optString(root, "player");
    dto.access_key = optString(root, "access_key");
    dto.album_id = optInt(root, "album_id");

    if(root.has("likes")){
        JsonObject likesRoot = root.getAsJsonObject("likes");
        dto.likes = optInt(likesRoot, "count");
        dto.user_likes = optIntAsBoolean(likesRoot, "user_likes");
    }

    dto.can_comment = optIntAsBoolean(root, "can_comment");
    dto.can_repost = optIntAsBoolean(root, "can_repost");
    dto.repeat = optIntAsBoolean(root, "repeat");

    if(root.has("privacy_view")){
        dto.privacy_view = context.deserialize(root.get("privacy_view"), VkApiPrivacy.class);
    }

    if(root.has("privacy_comment")){
        dto.privacy_comment = context.deserialize(root.get("privacy_comment"), VkApiPrivacy.class);
    }

    if(root.has("files")){
        JsonObject filesRoot = root.getAsJsonObject("files");
        dto.mp4_240 = optString(filesRoot, "mp4_240");
        dto.mp4_360 = optString(filesRoot, "mp4_360");
        dto.mp4_480 = optString(filesRoot, "mp4_480");
        dto.mp4_720 = optString(filesRoot, "mp4_720");
        dto.mp4_1080 = optString(filesRoot, "mp4_1080");
        dto.external = optString(filesRoot, "external");
    }

    dto.photo_130 = optString(root, "photo_130");
    dto.photo_320 = optString(root, "photo_320");
    dto.photo_800 = optString(root, "photo_800");
    dto.platform = optString(root, "platform");

    dto.can_edit = optIntAsBoolean(root, "can_edit");
    dto.can_add = optIntAsBoolean(root, "can_add");
    return dto;
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:69,代码来源:VideoDtoAdapter.java

示例15: fromJson

import com.google.gson.JsonElement; //导入方法依赖的package包/类
@Override
public Integer fromJson(final JsonElement json)
{
    return json.getAsInt();
}
 
开发者ID:Leviathan-Studio,项目名称:MineIDE,代码行数:6,代码来源:DataTypeList.java


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