本文整理匯總了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());
}
示例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;
}