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