Added support for JSON-LD arrays

pull/214/head
M66B 1 year ago
parent 096a493d95
commit d2368b49ab

@ -35,14 +35,17 @@ import java.util.Iterator;
// https://structured.email/content/introduction/getting_started.html // https://structured.email/content/introduction/getting_started.html
public class JsonLd { public class JsonLd {
private JSONObject jroot; private Object jroot;
private Throwable error = null; private Throwable error = null;
private static final String URI_SCHEMA_ORG = "https://schema.org/"; private static final String URI_SCHEMA_ORG = "https://schema.org/";
public JsonLd(String json) { public JsonLd(String json) {
try { try {
jroot = new JSONObject(json); if (json != null && json.trim().startsWith("["))
jroot = new JSONArray(json);
else
jroot = new JSONObject(json);
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(ex); Log.e(ex);
error = ex; error = ex;
@ -104,8 +107,11 @@ public class JsonLd {
} }
} else if (obj instanceof JSONArray) { } else if (obj instanceof JSONArray) {
JSONArray jarray = (JSONArray) obj; JSONArray jarray = (JSONArray) obj;
for (int i = 0; i < jarray.length(); i++) for (int i = 0; i < jarray.length(); i++) {
if (indent == 0 && i > 0)
holder.appendElement("br");
getHtml(jarray.get(i), indent, holder); getHtml(jarray.get(i), indent, holder);
}
} else { } else {
indent(indent, holder); indent(indent, holder);
String v = (obj == null ? "" : obj.toString()); String v = (obj == null ? "" : obj.toString());

Loading…
Cancel
Save