easier JSON parsing

This commit is contained in:
Grahame Grieve 2019-04-15 21:45:44 +10:00
parent cf6a4bb51f
commit 7ae0db763a
1 changed files with 16 additions and 0 deletions

View File

@ -1,6 +1,8 @@
package org.hl7.fhir.utilities.json;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/*-
* #%L
@ -68,4 +70,18 @@ public class JSONUtil {
return null;
}
public static String str(JsonObject json, String name) {
JsonElement e = json.get(name);
return e == null ? null : e.getAsString();
}
public static List<JsonObject> objects(JsonObject json, String name) {
List<JsonObject> res = new ArrayList<>();
if (json.has(name))
for (JsonElement e : json.getAsJsonArray(name))
if (e instanceof JsonObject)
res.add((JsonObject) e);
return res;
}
}