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


Java JsonObject.get方法代码示例

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


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

示例1: update

import com.google.gson.JsonObject; //导入方法依赖的package包/类
/**
 * Method to update config.
 * @param oldObj the old object
 * @param updatedObj the updated object
 */
private void update(final JsonObject oldObj, final JsonObject updatedObj) {
    for (Map.Entry<String, JsonElement> entry : updatedObj.getAsJsonObject().entrySet()) {
        if (!oldObj.has(entry.getKey())) {
            LOGGER.fine(String.format("%s does not exists, updating value.", entry.getKey()));
            oldObj.add(entry.getKey(), entry.getValue());
            continue;
        }

        JsonElement element = oldObj.get(entry.getKey());

        if (entry.getValue().isJsonObject()) {
            LOGGER.fine(String.format("%s is an object, processing object fields.", entry.getKey()));
            update(element.getAsJsonObject(), element.getAsJsonObject());
        } else {
            LOGGER.fine(String.format("Setting %s to %s.", entry.getKey(), entry.getValue().toString()));
            oldObj.add(entry.getKey(), entry.getValue());
        }
    }
}
 
开发者ID:enjin,项目名称:Enjin-Coin-Java-SDK,代码行数:25,代码来源:JsonConfig.java

示例2: transformData

import com.google.gson.JsonObject; //导入方法依赖的package包/类
@Override
public Map<Long, String> transformData(Map<Long, String> retrievedData) {
    Map<Long, String> transformedData = new HashMap<>();
    for (Map.Entry<Long, String> entry : retrievedData.entrySet()) {

        if (StringUtils.isEmpty(entry.getValue())) {
            continue;
        }
        JsonElement initialFilterJsonElement = new JsonParser().parse(entry.getValue());
        JsonObject filterJsonObject = initialFilterJsonElement.getAsJsonObject();
        JsonElement targetSpaceJsonElement = filterJsonObject.get(TARGET_SPACE);
        if (targetSpaceJsonElement == null) {
            continue;
        }

        CloudTarget cloudTarget = ConfigurationEntriesUtil.splitTargetSpaceValue(targetSpaceJsonElement.getAsString());
        JsonElement cloudTargetJsonElement = new Gson().toJsonTree(cloudTarget);
        filterJsonObject.add(TARGET_SPACE, cloudTargetJsonElement);
        transformedData.put(entry.getKey(), filterJsonObject.toString());

        logger.debug(String.format("Transform data for row ID: '%s' , Filter: '%s'", entry.getKey(), filterJsonObject.toString()));
    }
    return transformedData;
}
 
开发者ID:SAP,项目名称:cf-mta-deploy-service,代码行数:25,代码来源:TransformFilterColumn.java

示例3: getString

import com.google.gson.JsonObject; //导入方法依赖的package包/类
/**
 * Get the string value for the specified property from the json Object.
 * @param args
 *              the json object
 * @param property
 *              the key
 * @param defaultValue
 *              if key doesn't exist in the json object, then return the default value
 * @return the value as a string
 */
public static String getString(JsonObject args, String property, String defaultValue) {
    String value = null;
    try {
        JsonElement obj = args.get(property);
        value = obj.getAsString();
    } catch (Exception e) {
        // ignore and return default value;
    }
    if (value == null) {
        return defaultValue;
    }
    value = value.trim();
    if (value.length() == 0) {
        return defaultValue;
    }
    return value;
}
 
开发者ID:Microsoft,项目名称:java-debug,代码行数:28,代码来源:JsonUtils.java

示例4: updateBindings

import com.google.gson.JsonObject; //导入方法依赖的package包/类
/**
 * "forcedBindings": {
	"person" : {"type":"uri", "value":""},
	"name" : {"type":"literal", "value":""}}}
	
 * @param selectedValue
 * @return
 */
public Bindings updateBindings(String selectedValue) {
	JsonElement elem;
	Bindings ret = new Bindings();
	if ((elem = doc.get("updates")) !=null)
		if((elem = elem.getAsJsonObject().get(selectedValue))!=null)
			if((elem = elem.getAsJsonObject().get("forcedBindings"))!=null) {
				for (Entry<String, JsonElement> binding : elem.getAsJsonObject().entrySet()) {
					JsonObject value = binding.getValue().getAsJsonObject();
					RDFTerm bindingValue = null;
			
					if (value.get("type")!=null){
						if(value.get("type").getAsString().equals("uri")) {
							bindingValue = new RDFTermURI(value.get("value").getAsString());
						}
						else {
							bindingValue = new RDFTermLiteral(value.get("value").getAsString());
						}
					}
					ret.addBinding(binding.getKey(), bindingValue);
				}
			}
	return ret;
}
 
开发者ID:vaimee,项目名称:sepatools,代码行数:32,代码来源:ApplicationProfile.java

示例5: parseBbox

import com.google.gson.JsonObject; //导入方法依赖的package包/类
public static BoundingBoxDto parseBbox(JsonObject asJsonObject, JsonDeserializationContext context) {
	BoundingBoxDto bboxDto = null;
	JsonElement bboxElement = asJsonObject.get("bbox");
	if (bboxElement != null) {
		double[] bbox = context.deserialize(bboxElement, double[].class);
		bboxDto = new BoundingBoxDto();
		if (bbox.length == TWO_DIMENSIONAL_BBOX_LENGTH) {
			bboxDto.setSouthWestCorner(new PositionDto(bbox[0], bbox[1]));
			bboxDto.setNorthEastCorner(new PositionDto(bbox[2], bbox[3]));
		} else {
			bboxDto.setSouthWestCorner(new PositionDto(bbox[0], bbox[1], bbox[2]));
			bboxDto.setNorthEastCorner(new PositionDto(bbox[3], bbox[4], bbox[5]));
		}

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

示例6: deserialize

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

  ImmutableHolder.Builder builder = ImmutableHolder.builder();

  if (root.has("id")) {
    builder.id(root.get("id").getAsString());
  }

  JsonElement value = root.get(VALUE_PROPERTY);
  if (value == null) {
    throw new JsonParseException(String.format("%s not found for %s in JSON", VALUE_PROPERTY, type));
  }

  if (value.isJsonObject()) {
    final String valueTypeName = value.getAsJsonObject().get(Holder.TYPE_PROPERTY).getAsString();
    try {
      Class<?> valueType = Class.forName(valueTypeName);
      builder.value(context.deserialize(value, valueType));
    } catch (ClassNotFoundException e) {
      throw new JsonParseException(String.format("Couldn't construct value class %s for %s", valueTypeName, type), e);
    }
  } else if (value.isJsonPrimitive()) {
    final JsonPrimitive primitive = value.getAsJsonPrimitive();
    if (primitive.isString()) {
      builder.value(primitive.getAsString());
    } else if (primitive.isNumber()) {
      builder.value(primitive.getAsInt());
    } else if (primitive.isBoolean()) {
      builder.value(primitive.getAsBoolean());
    }
  } else {
    throw new JsonParseException(
        String.format("Couldn't deserialize %s : %s. Not a primitive or object", VALUE_PROPERTY, value));
  }

  return builder.build();

}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:41,代码来源:HolderJsonSerializer.java

示例7: parseMetadataSection

import com.google.gson.JsonObject; //导入方法依赖的package包/类
public <T extends IMetadataSection> T parseMetadataSection(String p_110503_1_, JsonObject p_110503_2_)
{
    if (p_110503_1_ == null)
    {
        throw new IllegalArgumentException("Metadata section name cannot be null");
    }
    else if (!p_110503_2_.has(p_110503_1_))
    {
        return (T)null;
    }
    else if (!p_110503_2_.get(p_110503_1_).isJsonObject())
    {
        throw new IllegalArgumentException("Invalid metadata for \'" + p_110503_1_ + "\' - expected object, found " + p_110503_2_.get(p_110503_1_));
    }
    else
    {
        IMetadataSerializer.Registration<?> registration = (IMetadataSerializer.Registration)this.metadataSectionSerializerRegistry.getObject(p_110503_1_);

        if (registration == null)
        {
            throw new IllegalArgumentException("Don\'t know how to handle metadata section \'" + p_110503_1_ + "\'");
        }
        else
        {
            return (T)((IMetadataSection)this.getGson().fromJson((JsonElement)p_110503_2_.getAsJsonObject(p_110503_1_), registration.field_110500_b));
        }
    }
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:29,代码来源:IMetadataSerializer.java

示例8: parseSectionsJson

import com.google.gson.JsonObject; //导入方法依赖的package包/类
private List<BookSection> parseSectionsJson(String name, InputStream inputstream) {
    BufferedReader br;
    try {
        br = new BufferedReader(new InputStreamReader(inputstream, "UTF-8"));
    } catch (UnsupportedEncodingException e) {
        Lector.logger.log(Level.ERROR, "Error reading file: " + name);
        return Collections.emptyList();
    }

    List<BookSection> sections = new ArrayList<>();

    JsonParser parser = new JsonParser();
    JsonElement element = parser.parse(br);
    for (JsonElement entry : element.getAsJsonArray()) {
        JsonObject object = entry.getAsJsonObject();

        JsonElement sectionElement = object.get("section");
        BookSection section;
        if (sectionElement != null) {
            section = new BookSection(sectionElement.getAsString());
        } else {
            section = new BookSection("");
        }
        sections.add(section);

        JsonElement textElement = object.get("text");
        boolean lastIsText = false;
        if (textElement != null) {
            for (JsonElement textChild : textElement.getAsJsonArray()) {
                if ((!textChild.isJsonPrimitive()) || !textChild.getAsJsonPrimitive().isString()) {
                    Lector.logger.log(Level.WARN, "File " + name + " has a problem in section " + section.getName());
                    continue;
                }
                String string = textChild.getAsString();
                if (string.equals("#")) {
                    section.addElement(new BookElementNewline());
                    lastIsText = false;
                } else if (string.equals("#>")) {
                    section.addElement(new BookElementNewline());
                    section.addElement(new BookElementIndent());
                    lastIsText = false;
                } else if (string.equals("##")) {
                    section.addElement(new BookElementNewParagraph());
                    lastIsText = false;
                } else if (string.equals("#-")) {
                    section.addElement(new BookElementRuler());
                    lastIsText = false;
                } else if (string.startsWith("#l")) {
                    lastIsText = parseLink(section, string);
                } else if (string.startsWith("#i")) {
                    lastIsText = parseItem(section, string);
                } else if (string.startsWith("#I")) {
                    lastIsText = parseImage(section, string);
                } else if (string.startsWith("#:")) {
                    lastIsText = parseFormattedText(section, lastIsText, string);
                } else {
                    lastIsText = handleText(section, lastIsText, string, "");
                }
            }
        }

        if (object.has("page")) {
            sections.add(new BookSection(null));    // Next page
        }
    }

    return sections;
}
 
开发者ID:McJty,项目名称:Lector,代码行数:69,代码来源:BookParser.java

示例9: setStartAndStop

import com.google.gson.JsonObject; //导入方法依赖的package包/类
private void setStartAndStop(WithStartAndStopReport report, JsonObject jsonReport){
    JsonElement start = jsonReport.get("startTime");
    report.setExecutionStartTime(start.getAsString());
    JsonElement stop = jsonReport.get("stopTime");
    report.setExecutionStopTime(stop.getAsString());
}
 
开发者ID:arquillian,项目名称:arquillian-reporter,代码行数:7,代码来源:ReportJsonDeserializer.java

示例10: deserialize

import com.google.gson.JsonObject; //导入方法依赖的package包/类
public FontMetadataSection deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
    JsonObject jsonobject = p_deserialize_1_.getAsJsonObject();
    float[] afloat = new float[256];
    float[] afloat1 = new float[256];
    float[] afloat2 = new float[256];
    float f = 1.0F;
    float f1 = 0.0F;
    float f2 = 0.0F;

    if (jsonobject.has("characters"))
    {
        if (!jsonobject.get("characters").isJsonObject())
        {
            throw new JsonParseException("Invalid font->characters: expected object, was " + jsonobject.get("characters"));
        }

        JsonObject jsonobject1 = jsonobject.getAsJsonObject("characters");

        if (jsonobject1.has("default"))
        {
            if (!jsonobject1.get("default").isJsonObject())
            {
                throw new JsonParseException("Invalid font->characters->default: expected object, was " + jsonobject1.get("default"));
            }

            JsonObject jsonobject2 = jsonobject1.getAsJsonObject("default");
            f = JsonUtils.getFloat(jsonobject2, "width", f);
            Validate.inclusiveBetween(0.0D, 3.4028234663852886E38D, (double)f, "Invalid default width");
            f1 = JsonUtils.getFloat(jsonobject2, "spacing", f1);
            Validate.inclusiveBetween(0.0D, 3.4028234663852886E38D, (double)f1, "Invalid default spacing");
            f2 = JsonUtils.getFloat(jsonobject2, "left", f1);
            Validate.inclusiveBetween(0.0D, 3.4028234663852886E38D, (double)f2, "Invalid default left");
        }

        for (int i = 0; i < 256; ++i)
        {
            JsonElement jsonelement = jsonobject1.get(Integer.toString(i));
            float f3 = f;
            float f4 = f1;
            float f5 = f2;

            if (jsonelement != null)
            {
                JsonObject jsonobject3 = JsonUtils.getJsonObject(jsonelement, "characters[" + i + "]");
                f3 = JsonUtils.getFloat(jsonobject3, "width", f);
                Validate.inclusiveBetween(0.0D, 3.4028234663852886E38D, (double)f3, "Invalid width");
                f4 = JsonUtils.getFloat(jsonobject3, "spacing", f1);
                Validate.inclusiveBetween(0.0D, 3.4028234663852886E38D, (double)f4, "Invalid spacing");
                f5 = JsonUtils.getFloat(jsonobject3, "left", f2);
                Validate.inclusiveBetween(0.0D, 3.4028234663852886E38D, (double)f5, "Invalid left");
            }

            afloat[i] = f3;
            afloat1[i] = f4;
            afloat2[i] = f5;
        }
    }

    return new FontMetadataSection(afloat, afloat2, afloat1);
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:62,代码来源:FontMetadataSectionSerializer.java

示例11: parsePlayerConfiguration

import com.google.gson.JsonObject; //导入方法依赖的package包/类
public PlayerConfiguration parsePlayerConfiguration(JsonElement p_parsePlayerConfiguration_1_)
{
    if (p_parsePlayerConfiguration_1_ == null)
    {
        throw new JsonParseException("JSON object is null, player: " + this.player);
    }
    else
    {
        JsonObject jsonobject = (JsonObject)p_parsePlayerConfiguration_1_;
        PlayerConfiguration playerconfiguration = new PlayerConfiguration();
        JsonArray jsonarray = (JsonArray)jsonobject.get("items");

        if (jsonarray != null)
        {
            for (int i = 0; i < jsonarray.size(); ++i)
            {
                JsonObject jsonobject1 = (JsonObject)jsonarray.get(i);
                boolean flag = Json.getBoolean(jsonobject1, "active", true);

                if (flag)
                {
                    String s = Json.getString(jsonobject1, "type");

                    if (s == null)
                    {
                        Config.warn("Item type is null, player: " + this.player);
                    }
                    else
                    {
                        String s1 = Json.getString(jsonobject1, "model");

                        if (s1 == null)
                        {
                            s1 = "items/" + s + "/model.cfg";
                        }

                        PlayerItemModel playeritemmodel = this.downloadModel(s1);

                        if (playeritemmodel != null)
                        {
                            if (!playeritemmodel.isUsePlayerTexture())
                            {
                                String s2 = Json.getString(jsonobject1, "texture");

                                if (s2 == null)
                                {
                                    s2 = "items/" + s + "/users/" + this.player + ".png";
                                }

                                BufferedImage bufferedimage = this.downloadTextureImage(s2);

                                if (bufferedimage == null)
                                {
                                    continue;
                                }

                                playeritemmodel.setTextureImage(bufferedimage);
                                ResourceLocation resourcelocation = new ResourceLocation("optifine.net", s2);
                                playeritemmodel.setTextureLocation(resourcelocation);
                            }

                            playerconfiguration.addPlayerItemModel(playeritemmodel);
                        }
                    }
                }
            }
        }

        return playerconfiguration;
    }
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:72,代码来源:PlayerConfigurationParser.java

示例12: deserialize

import com.google.gson.JsonObject; //导入方法依赖的package包/类
public AnimationMetadataSection deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
    List<AnimationFrame> list = Lists.<AnimationFrame>newArrayList();
    JsonObject jsonobject = JsonUtils.getJsonObject(p_deserialize_1_, "metadata section");
    int i = JsonUtils.getInt(jsonobject, "frametime", 1);

    if (i != 1)
    {
        Validate.inclusiveBetween(1L, 2147483647L, (long)i, "Invalid default frame time");
    }

    if (jsonobject.has("frames"))
    {
        try
        {
            JsonArray jsonarray = JsonUtils.getJsonArray(jsonobject, "frames");

            for (int j = 0; j < jsonarray.size(); ++j)
            {
                JsonElement jsonelement = jsonarray.get(j);
                AnimationFrame animationframe = this.parseAnimationFrame(j, jsonelement);

                if (animationframe != null)
                {
                    list.add(animationframe);
                }
            }
        }
        catch (ClassCastException classcastexception)
        {
            throw new JsonParseException("Invalid animation->frames: expected array, was " + jsonobject.get("frames"), classcastexception);
        }
    }

    int k = JsonUtils.getInt(jsonobject, "width", -1);
    int l = JsonUtils.getInt(jsonobject, "height", -1);

    if (k != -1)
    {
        Validate.inclusiveBetween(1L, 2147483647L, (long)k, "Invalid width");
    }

    if (l != -1)
    {
        Validate.inclusiveBetween(1L, 2147483647L, (long)l, "Invalid height");
    }

    boolean flag = JsonUtils.getBoolean(jsonobject, "interpolate", false);
    return new AnimationMetadataSection(list, k, l, i, flag);
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:51,代码来源:AnimationMetadataSectionSerializer.java

示例13: deserialize

import com.google.gson.JsonObject; //导入方法依赖的package包/类
@Override
public Variant deserialize ( final JsonElement json, final Type typeOfT, final JsonDeserializationContext context ) throws JsonParseException
{
    if ( json.isJsonNull () )
    {
        return null;
    }

    if ( json instanceof JsonPrimitive )
    {
        return decodeFromPrimitive ( json );
    }

    if ( json instanceof JsonObject )
    {
        final JsonObject jsonObj = (JsonObject)json;
        final JsonElement type = jsonObj.get ( VariantJson.FIELD_TYPE );
        final JsonElement value = jsonObj.get ( VariantJson.FIELD_VALUE );

        if ( type == null || type.isJsonNull () )
        {
            if ( value == null )
            {
                throw new JsonParseException ( String.format ( "Variant encoded as object must have a field '%s'", VariantJson.FIELD_VALUE ) );
            }
            return Variant.valueOf ( value.getAsString () );
        }

        if ( !type.isJsonPrimitive () )
        {
            throw new JsonParseException ( String.format ( "Variant field '%s' must be a string containing the variant type (%s)", VariantJson.FIELD_TYPE, StringHelper.join ( VariantType.values (), ", " ) ) );
        }

        final String typeStr = type.getAsString ();

        if ( typeStr.equals ( "NULL" ) )
        {
            return Variant.NULL;
        }

        if ( value == null || value.isJsonNull () )
        {
            throw new JsonParseException ( String.format ( "The type '%s' does not support a null value. Use variant type NULL instead.", typeStr ) );
        }

        if ( value.isJsonObject () || value.isJsonArray () )
        {
            throw new JsonParseException ( "The variant value must be a JSON primitive matching the type. Arrays and objects are not supported" );
        }

        switch ( type.getAsString () )
        {
            case "BOOLEAN":
                return Variant.valueOf ( value.getAsBoolean () );
            case "STRING":
                return Variant.valueOf ( value.getAsString () );
            case "DOUBLE":
                return Variant.valueOf ( value.getAsDouble () );
            case "INT32":
                return Variant.valueOf ( value.getAsInt () );
            case "INT64":
                return Variant.valueOf ( value.getAsLong () );
            default:
                throw new JsonParseException ( String.format ( "Type '%s' is unknown (known types: %s)", StringHelper.join ( VariantType.values (), ", " ) ) );
        }
    }

    throw new JsonParseException ( "Unknown serialization of Variant type" );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:70,代码来源:VariantJsonDeserializer.java

示例14: getLanguage

import com.google.gson.JsonObject; //导入方法依赖的package包/类
public String getLanguage(String variable){
	if(solution.get(variable) == null) return null;
	JsonObject json = solution.get(variable).getAsJsonObject();
	if (json.get("xml:lang") == null) return null;
	return json.get("xml:lang").getAsString();
}
 
开发者ID:vaimee,项目名称:sepatools,代码行数:7,代码来源:Bindings.java

示例15: getFloat

import com.google.gson.JsonObject; //导入方法依赖的package包/类
public static float getFloat(JsonObject p_getFloat_0_, String p_getFloat_1_, float p_getFloat_2_)
{
    JsonElement jsonelement = p_getFloat_0_.get(p_getFloat_1_);
    return jsonelement == null ? p_getFloat_2_ : jsonelement.getAsFloat();
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:6,代码来源:Json.java


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