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


Java JsonElement.getAsJsonObject方法代码示例

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


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

示例1: deserialize

import com.google.gson.JsonElement; //导入方法依赖的package包/类
@Override
public MultiPointDto deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) {

	MultiPointDto dto = new MultiPointDto();
	List<PositionDto> positions = new ArrayList<>();
	dto.setPositions(positions);

	JsonObject asJsonObject = json.getAsJsonObject();
	JsonArray jsonArray = asJsonObject.get("coordinates").getAsJsonArray();
	for (int i = 0; i < jsonArray.size(); i++) {
		PositionDto position = context.deserialize(jsonArray.get(i), PositionDto.class);
		positions.add(position);
	}

	dto.setBbox(BoundingBoxParser.parseBbox(asJsonObject, context));

	return dto;
}
 
开发者ID:mokszr,项目名称:ultimate-geojson,代码行数:19,代码来源:MultiPointDeserializer.java

示例2: deserialize

import com.google.gson.JsonElement; //导入方法依赖的package包/类
@Override
public FeatureCollectionDto deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) {

	FeatureCollectionDto dto = new FeatureCollectionDto();
	List<FeatureDto> features = new ArrayList<>();
	dto.setFeatures(features);

	JsonObject asJsonObject = json.getAsJsonObject();
	JsonArray jsonArray = asJsonObject.get("features").getAsJsonArray();
	if (jsonArray == null) {
		return dto;
	}

	for (int i = 0; i < jsonArray.size(); i++) {
		JsonObject featureElement = jsonArray.get(i).getAsJsonObject();
		FeatureDto geometryDto = context.deserialize(featureElement, FeatureDto.class);
		features.add(geometryDto);
	}

	dto.setBbox(BoundingBoxParser.parseBbox(asJsonObject, context));

	return dto;
}
 
开发者ID:mokszr,项目名称:ultimate-geojson,代码行数:24,代码来源:FeatureCollectionDeserializer.java

示例3: deserialize

import com.google.gson.JsonElement; //导入方法依赖的package包/类
@Override
public DbFreezeMode deserialize(JsonElement json,
                                Type typeOfT,
                                JsonDeserializationContext context)
{
  DbFreezeMode mode = null;
  if (json.isJsonObject())
  {
    JsonObject jsonObject = json.getAsJsonObject();
    JsonElement codeElement = jsonObject.get("code");
    if (codeElement != null)
    {
      String code = codeElement.getAsString();
      mode = DbFreezeMode.fromCode(code);
    }
  }
  if (mode == null)
  {
    throw new JsonParseException("Could not deserialize json string as DbFreezeMode: " + json);
  }
  return mode;
}
 
开发者ID:Nike-Inc,项目名称:bluegreen-manager,代码行数:23,代码来源:DbFreezeModeJsonDeserializer.java

示例4: testBodyReading

import com.google.gson.JsonElement; //导入方法依赖的package包/类
public void testBodyReading(String first, String second) throws IOException {
    ServletInputStream x = (ServletInputStream) new RpcHandlerTest_InputStream(second);
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    Map<String, Set<String>> headers = new TreeMap<>();
    when(request.getHeaderNames())
            .thenReturn(
                    new RpcReadExceptionTest.RpcHandlerTest_IteratorEnumeration<>(headers.keySet().iterator())
            );

    when(request.getInputStream()).thenReturn(x);
    when(request.getRequestURL())
            .thenReturn(new StringBuffer("http://fizz.buzz"));

    RpcReadException rpcReadException = new RpcReadException(first.getBytes(), x, "i am a message");
    String json = rpcReadException.toJson(request);

    try {
        JsonElement root = new JsonParser().parse(json);
        JsonObject jsob = root.getAsJsonObject();
        JsonElement b = jsob.get("request_body");
        Assert.assertNotNull(b);
        Assert.assertEquals(first+second, this.decode(b.getAsString()));
    } catch (Exception ex) {
        Assert.fail(ex.toString());
    }
}
 
开发者ID:Sixt,项目名称:ja-micro,代码行数:27,代码来源:RpcReadExceptionTest.java

示例5: 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

示例6: LoadSaal

import com.google.gson.JsonElement; //导入方法依赖的package包/类
public void LoadSaal(String path) throws FileNotFoundException {
    parser = new JsonParser();
    UUID kinoId = UUID.randomUUID();
    Object obj = parser.parse(new FileReader(path));

    JsonArray saale = (JsonArray) obj;

    for (JsonElement j : saale) {
        JsonObject jsonObject = j.getAsJsonObject();


        for (Kino i : Kinobuchungsystem.Kinos
                ) {
            if (i.getID().equals(jsonObject.get("id").getAsString())) {
                kinoId = i.getID();
            }

            Kinobuchungsystem.saale.add(
                    new Saal(
                            jsonObject.get("id").getAsString(),
                            jsonObject.get("anzahlSitzplaetze").getAsString(),
                            jsonObject.get("name").getAsString(),
                            jsonObject.get("leinwandhoehe").getAsString(),
                            kinoId,
                            jsonObject.get("dreidfaehigkeit").getAsBoolean()
                    )
            );
        }
    }
}
 
开发者ID:fabianbaechli,项目名称:kino_system,代码行数:31,代码来源:LoadFromJSON.java

示例7: getJsonObject

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

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

示例8: deserialize

import com.google.gson.JsonElement; //导入方法依赖的package包/类
@Override
public Result deserialize(JsonElement je, Type type, JsonDeserializationContext jdc)
    throws JsonParseException {
  JsonObject content = je.getAsJsonObject();
  ResultType resultType = jdc.deserialize(content.get("type"), ResultType.class);
  return jdc.deserialize(content.get(resultType.getName()), resultType.getType());
}
 
开发者ID:FelixGail,项目名称:gplaymusic,代码行数:8,代码来源:ResultDeserializer.java

示例9: deserialize

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

    String type = optString(root, "type");
    VkApiBaseFeedback dto = createInstance(type);

    if (Objects.nonNull(dto)) {
        Parser parser = getParser(type);
        parser.parse(root, dto, context);
    }

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

示例10: deserialize

import com.google.gson.JsonElement; //导入方法依赖的package包/类
public TextureMetadataSection deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
    JsonObject jsonobject = p_deserialize_1_.getAsJsonObject();
    boolean flag = JsonUtils.getBoolean(jsonobject, "blur", false);
    boolean flag1 = JsonUtils.getBoolean(jsonobject, "clamp", false);
    return new TextureMetadataSection(flag, flag1);
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:8,代码来源:TextureMetadataSectionSerializer.java

示例11: deserialize

import com.google.gson.JsonElement; //导入方法依赖的package包/类
public BlockPartFace deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
    JsonObject jsonobject = p_deserialize_1_.getAsJsonObject();
    EnumFacing enumfacing = this.parseCullFace(jsonobject);
    int i = this.parseTintIndex(jsonobject);
    String s = this.parseTexture(jsonobject);
    BlockFaceUV blockfaceuv = (BlockFaceUV)p_deserialize_3_.deserialize(jsonobject, BlockFaceUV.class);
    return new BlockPartFace(enumfacing, i, s, blockfaceuv);
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:10,代码来源:BlockPartFace.java

示例12: deserialize

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

    VKApiTopic dto = new VKApiTopic();
    dto.id = optInt(root, "id");
    dto.owner_id = optInt(root, "owner_id");
    dto.title = optString(root, "title");
    dto.created = optLong(root, "created");
    dto.created_by = optInt(root, "created_by");
    dto.updated = optInt(root, "updated");
    dto.updated_by = optInt(root, "updated_by");
    dto.is_closed = optIntAsBoolean(root, "is_closed");
    dto.is_fixed = optIntAsBoolean(root, "is_fixed");

    JsonElement commentsJson = root.get("comments");
    if(nonNull(commentsJson)){
        if(commentsJson.isJsonObject()){
            dto.comments = context.deserialize(commentsJson, CommentsDto.class);
        } else {
            dto.comments = new CommentsDto();
            dto.comments.count = commentsJson.getAsInt();
        }
    }

    dto.first_comment = optString(root, "first_comment");
    dto.last_comment = optString(root, "last_comment");
    return dto;
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:30,代码来源:ToticDtoAdapter.java

示例13: createOrder

import com.google.gson.JsonElement; //导入方法依赖的package包/类
@Override
public String createOrder(final Order order)
{
    try
    {
        String response = Util.postWebResponse("https://www.creeperhost.net/json/order/" + order.clientID + "/" + order.productID + "/" + order.serverLocation, new HashMap<String, String>()
        {{
            put("name", order.name);
            put("swid", Config.getInstance().getVersion());
            if (order.pregen)
                put("pregen", String.valueOf(Config.getInstance().getPregenDiameter()));
        }});

        if (response.equals("error"))
        {

        }
        else
        {
            JsonElement jElement = new JsonParser().parse(response);
            JsonObject jObject = jElement.getAsJsonObject();
            if (jObject.getAsJsonPrimitive("status").getAsString().equals("success"))
            {
                jObject = jObject.getAsJsonObject("more");
                return "success:" + jObject.getAsJsonPrimitive("invoiceid").getAsString() + ":" + jObject.getAsJsonPrimitive("orderid").getAsString();
            }
            else
            {
                return jObject.getAsJsonPrimitive("message").getAsString();
            }
        }
        return "Unknown error";
    }
    catch (Throwable t)
    {
        CreeperHost.logger.error("Unable to create order");
        return "Unknown error";
    }
}
 
开发者ID:CreeperHost,项目名称:CreeperHostGui,代码行数:40,代码来源:CreeperHostServerHost.java

示例14: deserialize

import com.google.gson.JsonElement; //导入方法依赖的package包/类
public ModelBlockDefinition.Variant deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
    JsonObject jsonobject = p_deserialize_1_.getAsJsonObject();
    String s = this.parseModel(jsonobject);
    ModelRotation modelrotation = this.parseRotation(jsonobject);
    boolean flag = this.parseUvLock(jsonobject);
    int i = this.parseWeight(jsonobject);
    return new ModelBlockDefinition.Variant(this.makeModelLocation(s), modelrotation, flag, i);
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:10,代码来源:ModelBlockDefinition.java

示例15: isResponseSuccess

import com.google.gson.JsonElement; //导入方法依赖的package包/类
public boolean isResponseSuccess(JsonElement jsonElement) {
    if (!jsonElement.isJsonNull()) {
        if (jsonElement.isJsonObject()) {
            JsonObject json = jsonElement.getAsJsonObject();
            //{"errors": ["Username is missing", "Password cannot be blank"]}
            return !json.has("errors");
        } else {
            return true;
        }
    } else {
        return false;
    }
}
 
开发者ID:alphater,项目名称:garras,代码行数:14,代码来源:DataManager.java


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