當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonObject.entrySet方法代碼示例

本文整理匯總了Java中com.google.gson.JsonObject.entrySet方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonObject.entrySet方法的具體用法?Java JsonObject.entrySet怎麽用?Java JsonObject.entrySet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.gson.JsonObject的用法示例。


在下文中一共展示了JsonObject.entrySet方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: parseValues

import com.google.gson.JsonObject; //導入方法依賴的package包/類
public static List<KvEntry> parseValues(JsonObject valuesObject) {
  List<KvEntry> result = new ArrayList<>();
  for (Entry<String, JsonElement> valueEntry : valuesObject.entrySet()) {
    JsonElement element = valueEntry.getValue();
    if (element.isJsonPrimitive()) {
      JsonPrimitive value = element.getAsJsonPrimitive();
      if (value.isString()) {
        result.add(new StringDataEntry(valueEntry.getKey(), value.getAsString()));
      } else if (value.isBoolean()) {
        result.add(new BooleanDataEntry(valueEntry.getKey(), value.getAsBoolean()));
      } else if (value.isNumber()) {
        if (value.getAsString().contains(".")) {
          result.add(new DoubleDataEntry(valueEntry.getKey(), value.getAsDouble()));
        } else {
          result.add(new LongDataEntry(valueEntry.getKey(), value.getAsLong()));
        }
      } else {
        throw new JsonSyntaxException("Can't parse value: " + value);
      }
    } else {
      throw new JsonSyntaxException("Can't parse value: " + element);
    }
  }
  return result;
}
 
開發者ID:osswangxining,項目名稱:iotplatform,代碼行數:26,代碼來源:JsonConverter.java

示例2: getAsCollection

import com.google.gson.JsonObject; //導入方法依賴的package包/類
@Override
public <T, C extends Collection<T>> void getAsCollection(String key, Class<T> type, C collection)
{
    JsonElement element = this.getElement(this.element, key);
    if (element == null)
    {
        throw new DeserializationException(type, this, "Can't find valid value for key: " + key);
    }
    if (element.isJsonArray())
    {
        JsonArray jsonArray = element.getAsJsonArray();
        for (JsonElement jsonElement : jsonArray)
        {
            collection.add(this.deserializeSpecial(type, jsonElement, null));
        }
    }
    else if (element.isJsonObject())
    {
        JsonObject jsonObject = element.getAsJsonObject();
        for (Entry<String, JsonElement> entry : jsonObject.entrySet())
        {
            collection.add(this.deserializeSpecial(type, entry.getValue(), null));
        }
    }
    else
    {
        throw new DeserializationException(type, this, "Can't find valid value for key: " + key);
    }
}
 
開發者ID:GotoFinal,項目名稱:diorite-configs-java8,代碼行數:30,代碼來源:JsonDeserializationData.java

示例3: parseScripts

import com.google.gson.JsonObject; //導入方法依賴的package包/類
public static final List<String> parseScripts(File f) {
    List<String> list = new ArrayList<>();
    if(!f.exists()) {
        return list;
    }

    try {
        JsonObject result = new Gson().fromJson(FileUtil.loadFile(f, "UTF-8"), JsonObject.class);
        JsonObject scripts = result.getAsJsonObject("scripts");
        if(scripts == null) {
            return list;// Fix NPE when there is an empty or no scripts package.json file
        }
        for (Map.Entry<String, JsonElement> obj:
                scripts.entrySet()) {
            list.add(obj.getKey());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return list;
}
 
開發者ID:beansoftapp,項目名稱:react-native-console,代碼行數:23,代碼來源:NPMParser.java

示例4: writeObservationsToJSON

import com.google.gson.JsonObject; //導入方法依賴的package包/類
@Override
public void writeObservationsToJSON(JsonObject json, MissionInit missionInit)
{
   	String jsonstring = "";
   	synchronized (this.latestJsonStats)
   	{
   		jsonstring = this.latestJsonStats;
	}
   	if (jsonstring.length() > 2)	// "{}" is the empty JSON string.
   	{
   		// Parse the string into json:
   		JsonParser parser = new JsonParser();
   		JsonElement root = parser.parse(jsonstring);
   		// Now copy the children of root into the provided json object:
   		if (root.isJsonObject())
   		{
   			JsonObject rootObj = root.getAsJsonObject();
			for (Map.Entry<String, JsonElement> entry : rootObj.entrySet())
			{
				json.add(entry.getKey(), entry.getValue());
			}
   		}
   	}
}
 
開發者ID:Yarichi,項目名稱:Proyecto-DASI,代碼行數:25,代碼來源:ObservationFromServer.java

示例5: parseFaces

import com.google.gson.JsonObject; //導入方法依賴的package包/類
private Map<EnumFacing, BlockPartFace> parseFaces(JsonDeserializationContext deserializationContext, JsonObject object)
{
    Map<EnumFacing, BlockPartFace> map = Maps.newEnumMap(EnumFacing.class);
    JsonObject jsonobject = JsonUtils.getJsonObject(object, "faces");

    for (Entry<String, JsonElement> entry : jsonobject.entrySet())
    {
        EnumFacing enumfacing = this.parseEnumFacing((String)entry.getKey());
        map.put(enumfacing, (BlockPartFace)deserializationContext.deserialize((JsonElement)entry.getValue(), BlockPartFace.class));
    }

    return map;
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:14,代碼來源:BlockPart.java

示例6: serializeFeedbackData

import com.google.gson.JsonObject; //導入方法依賴的package包/類
private void serializeFeedbackData(NavigationFeedbackEvent src, JsonSerializationContext context,
                                   JsonObject feedbackEvent) {
  JsonObject feedbackData = context.serialize(src.getFeedbackData()).getAsJsonObject();
  for (Map.Entry<String, JsonElement> e : feedbackData.entrySet()) {
    feedbackEvent.add(e.getKey(), e.getValue());
  }
}
 
開發者ID:mapbox,項目名稱:mapbox-events-android,代碼行數:8,代碼來源:FeedbackEventSerializer.java

示例7: parseResource

import com.google.gson.JsonObject; //導入方法依賴的package包/類
private static Resource parseResource(JsonObject object, String name, Resource parent) {
	ResourceMock resource = new ResourceMock(parent, name);
	for (Entry<String, JsonElement> entry : object.entrySet()) {
		resource.addChild(parseResource(entry.getValue(), entry.getKey(), resource));
	}
	return resource;
}
 
開發者ID:apache,項目名稱:sling-org-apache-sling-query,代碼行數:8,代碼來源:JsonToResource.java

示例8: parseFaces

import com.google.gson.JsonObject; //導入方法依賴的package包/類
private Map<EnumFacing, BlockPartFace> parseFaces(JsonDeserializationContext p_178253_1_, JsonObject p_178253_2_)
{
    Map<EnumFacing, BlockPartFace> map = Maps.newEnumMap(EnumFacing.class);
    JsonObject jsonobject = JsonUtils.getJsonObject(p_178253_2_, "faces");

    for (Entry<String, JsonElement> entry : jsonobject.entrySet())
    {
        EnumFacing enumfacing = this.parseEnumFacing((String)entry.getKey());
        map.put(enumfacing, (BlockPartFace)p_178253_1_.deserialize((JsonElement)entry.getValue(), BlockPartFace.class));
    }

    return map;
}
 
開發者ID:Notoh,項目名稱:DecompiledMinecraft,代碼行數:14,代碼來源:BlockPart.java

示例9: deserialize

import com.google.gson.JsonObject; //導入方法依賴的package包/類
public LanguageMetadataSection deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
    JsonObject jsonobject = p_deserialize_1_.getAsJsonObject();
    Set<Language> set = Sets.<Language>newHashSet();

    for (Entry<String, JsonElement> entry : jsonobject.entrySet())
    {
        String s = (String)entry.getKey();
        JsonObject jsonobject1 = JsonUtils.getJsonObject((JsonElement)entry.getValue(), "language");
        String s1 = JsonUtils.getString(jsonobject1, "region");
        String s2 = JsonUtils.getString(jsonobject1, "name");
        boolean flag = JsonUtils.getBoolean(jsonobject1, "bidirectional", false);

        if (s1.isEmpty())
        {
            throw new JsonParseException("Invalid language->\'" + s + "\'->region: empty value");
        }

        if (s2.isEmpty())
        {
            throw new JsonParseException("Invalid language->\'" + s + "\'->name: empty value");
        }

        if (!set.add(new Language(s, s1, s2, flag)))
        {
            throw new JsonParseException("Duplicate language->\'" + s + "\' defined");
        }
    }

    return new LanguageMetadataSection(set);
}
 
開發者ID:SkidJava,項目名稱:BaseClient,代碼行數:32,代碼來源:LanguageMetadataSectionSerializer.java

示例10: serializeChatStyle

import com.google.gson.JsonObject; //導入方法依賴的package包/類
private void serializeChatStyle(ChatStyle style, JsonObject object, JsonSerializationContext ctx)
{
    JsonElement jsonelement = ctx.serialize(style);

    if (jsonelement.isJsonObject())
    {
        JsonObject jsonobject = (JsonObject)jsonelement;

        for (Entry<String, JsonElement> entry : jsonobject.entrySet())
        {
            object.add((String)entry.getKey(), (JsonElement)entry.getValue());
        }
    }
}
 
開發者ID:SkidJava,項目名稱:BaseClient,代碼行數:15,代碼來源:IChatComponent.java

示例11: serializeChatStyle

import com.google.gson.JsonObject; //導入方法依賴的package包/類
private void serializeChatStyle(Style style, JsonObject object, JsonSerializationContext ctx)
{
    JsonElement jsonelement = ctx.serialize(style);

    if (jsonelement.isJsonObject())
    {
        JsonObject jsonobject = (JsonObject)jsonelement;

        for (Entry<String, JsonElement> entry : jsonobject.entrySet())
        {
            object.add((String)entry.getKey(), (JsonElement)entry.getValue());
        }
    }
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:15,代碼來源:ITextComponent.java

示例12: Mutation

import com.google.gson.JsonObject; //導入方法依賴的package包/類
public Mutation(JsonObject fields) throws SchemaViolationError {
    for (Map.Entry<String, JsonElement> field : fields.entrySet()) {
        String key = field.getKey();
        String fieldName = getFieldName(key);
        switch (fieldName) {
            case "set_integer": {
                responseData.put(key, jsonAsBoolean(field.getValue(), key));

                break;
            }

            case "set_string": {
                responseData.put(key, jsonAsBoolean(field.getValue(), key));

                break;
            }

            case "set_string_with_default": {
                responseData.put(key, jsonAsBoolean(field.getValue(), key));

                break;
            }

            case "__typename": {
                responseData.put(key, jsonAsString(field.getValue(), key));
                break;
            }
            default: {
                throw new SchemaViolationError(this, key, field.getValue());
            }
        }
    }
}
 
開發者ID:Shopify,項目名稱:graphql_java_gen,代碼行數:34,代碼來源:Generated.java

示例13: makeMapResourceValues

import com.google.gson.JsonObject; //導入方法依賴的package包/類
protected Map<ResourceLocation, Float> makeMapResourceValues(JsonObject p_188025_1_)
{
    Map<ResourceLocation, Float> map = Maps.<ResourceLocation, Float>newLinkedHashMap();
    JsonObject jsonobject = JsonUtils.getJsonObject(p_188025_1_, "predicate");

    for (Entry<String, JsonElement> entry : jsonobject.entrySet())
    {
        map.put(new ResourceLocation((String)entry.getKey()), Float.valueOf(JsonUtils.getFloat((JsonElement)entry.getValue(), (String)entry.getKey())));
    }

    return map;
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:13,代碼來源:ItemOverride.java

示例14: parseRoomEvents

import com.google.gson.JsonObject; //導入方法依賴的package包/類
private void parseRoomEvents(JsonObject syncData) throws RestfulHTTPException, IOException {
	if(syncData.has("rooms") &&
			syncData.get("rooms").isJsonObject()) {

		JsonObject roomsData = syncData.get("rooms").getAsJsonObject();

		if(roomsData.has("join") &&
				roomsData.get("join").isJsonObject()) {
			JsonObject joinEvents = roomsData.get("join").getAsJsonObject();
			for(Map.Entry<String, JsonElement> joinEventEntry : joinEvents.entrySet()) {
				if(joinEventEntry.getValue().isJsonObject()) {
					String roomId = joinEventEntry.getKey();
					JsonObject joinEvent = joinEventEntry.getValue().getAsJsonObject();
					Room room;
					if(joinRooms.containsKey(roomId)) {
						room = joinRooms.get(roomId);
					}else{
						room = new Room(api, users, roomId);
					}
					room.update(joinEvent);
					joinRooms.put(roomId, room);
				}
			}
		}

		// TODO: "leave"-rooms
		// TODO: "invite"-rooms
	}
}
 
開發者ID:Gurgy,項目名稱:Cypher,代碼行數:30,代碼來源:Client.java

示例15: Plain

import com.google.gson.JsonObject; //導入方法依賴的package包/類
@SuppressWarnings("WeakerAccess")
public Plain(String json) {
    List<JsonTable> list = new ArrayList<>();
    if (StringUtils.isNoneEmpty(json)) {
        final JsonParser parser = new JsonParser();
        final JsonObject jsonObject = parser.parse(json).getAsJsonObject();
        for (Map.Entry<String, JsonElement> e : jsonObject.entrySet()) {
            if (e.getValue().isJsonArray()) {
                list.add(new JsonTable(e.getKey(), e.getValue().getAsJsonArray()));
            }
        }
    }
    jsonLength = json.length();
    iterator = list.iterator();
}
 
開發者ID:terma,項目名稱:sql-on-json,代碼行數:16,代碼來源:Plain.java


注:本文中的com.google.gson.JsonObject.entrySet方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。