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


Java JsonObject.keySet方法代码示例

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


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

示例1: getSports

import com.google.gson.JsonObject; //导入方法依赖的package包/类
private Response getSports() {
    StringBuilder out = new StringBuilder("#EXTM3U\n");
    List<Event> events = new ArrayList<>();
    Date now = new Date();

    JsonObject map = HttpClient.getJson("https://guide.smoothstreams.tv/feed.json");
    if (map != null) for (String key : map.keySet()) {
        JsonObject jO = map.getAsJsonObject(key);

        JsonArray jA = jO.getAsJsonArray("items");
        if (jA != null) for (JsonElement jE : jA) {
            jO = jE.getAsJsonObject();

            Date time = Event.getDate(jO.getAsJsonPrimitive("time").getAsString());
            if (Event.isDate(now, time)) {
                int num = jO.getAsJsonPrimitive("channel").getAsInt();
                String group = jO.getAsJsonPrimitive("category").getAsString();
                String quality = jO.getAsJsonPrimitive("quality").getAsString();
                String language = jO.getAsJsonPrimitive("language").getAsString();
                String name = HttpClient.decode(jO.getAsJsonPrimitive("name").getAsString());

                events.add(new Event(num, name, time, !group.isEmpty() ? group : "~UNKNOWN~", quality, language));
            }
        }
    }

    int nonce = 0;
    Collections.sort(events);
    String pattern = ipc.getPattern();

    for (Event e : events) {
        out.append(String.format(Locale.US, "#EXTINF:-1 group-title=\"%s\" tvg-id=\"%s\" tvg-logo=\"https://guide.smoothstreams.tv/assets/images/events/%s.png\",%s\nhttp://%s:%s/playlist.m3u8?ch=%02d&nonce=%02d\n",
                e.group, e.num, e.num, e.getEvent(pattern), host, port, e.num, ++nonce));
    }

    return newFixedLengthResponse(Response.Status.OK, "application/vnd.apple.mpegurl", out.toString());
}
 
开发者ID:mr-notorious,项目名称:SmoothProxy,代码行数:38,代码来源:SmoothProxy.java

示例2: matchesSafely

import com.google.gson.JsonObject; //导入方法依赖的package包/类
@Override
protected boolean matchesSafely(
	JsonObject jsonObject, Description description) {

	Map<String, Consumer<Description>> mismatchedKeys = new HashMap<>();

	_entryMatchers.forEach(
		(key, value) -> {
			JsonElement jsonElement = jsonObject.get(key);

			if (!value.matches(jsonElement)) {
				mismatchedKeys.put(
					key,
					consumerDescription -> value.describeMismatch(
						jsonElement, consumerDescription));
			}
		});

	Set<String> keys = _entryMatchers.keySet();

	if (!mismatchedKeys.isEmpty()) {
		description.appendText("was a JSON object ");

		describeNestedMismatches(
			keys, description, mismatchedKeys,
			(text, innerDescription) -> innerDescription.appendText(text));

		return false;
	}

	if (_strictMode && (jsonObject.size() > _entryMatchers.size())) {
		Set<String> jsonObjectKeys = new HashSet<>(jsonObject.keySet());

		jsonObjectKeys.removeAll(keys);

		Stream<String> stream = jsonObjectKeys.stream();

		String extraKeys = stream.collect(Collectors.joining(", "));

		description.appendText(
			"was a JSON object "
		).appendText(
			"with more fields than validated. "
		).appendText(
			"Extra keys: "
		).appendText(
			extraKeys
		);

		return false;
	}

	return true;
}
 
开发者ID:liferay,项目名称:com-liferay-apio-architect,代码行数:55,代码来源:IsJsonObject.java


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