Skip to content

Commit

Permalink
initial orfon crawler
Browse files Browse the repository at this point in the history
  • Loading branch information
pidoubleyou committed Mar 24, 2024
1 parent ceaf209 commit d10f523
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/main/java/mServer/crawler/sender/base/JsonUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,18 @@ public static boolean hasStringElements(
}

public static Optional<String> getElementValueAsString(final JsonElement aJsonElement, final String... aElementIds) {
Optional<String> rs = Optional.empty();
Optional<JsonElement> rs = JsonUtils.getElement(aJsonElement, aElementIds);
if (rs.isPresent()) {
return Optional.of(rs.get().getAsString());
}
return Optional.empty();
}

public static Optional<JsonElement> getElement(final JsonElement aJsonElement, final String... aElementIds) {
Optional<JsonElement> rs = Optional.empty();
if (aElementIds == null || aElementIds.length == 0) {
return rs;
}
JsonObject aJsonObject = aJsonElement.getAsJsonObject();
for (int i = 0; i < aElementIds.length-1; i++) {
String elementId = aElementIds[i];
Expand All @@ -147,7 +158,7 @@ public static Optional<String> getElementValueAsString(final JsonElement aJsonEl
//
String elementId = aElementIds[aElementIds.length-1];
if (aJsonObject != null && aJsonObject.has(elementId) && !aJsonObject.get(elementId).isJsonNull()) {
rs = Optional.of(aJsonObject.get(elementId).getAsString());
rs = Optional.of(aJsonObject.get(elementId));
}
//
return rs;
Expand Down

0 comments on commit d10f523

Please sign in to comment.