@SuppressWarnings("unchecked") private void jsonToHTML(JSON json, StringBuilder sb) { if (json == null || json.isEmpty()) { return; } if (json.isArray()) { Object[] oa = ((JSONArray) json).toArray(); sb.append("<table border=\"1\">\n"); for (Object o : oa) { sb.append("<tr><td>\n"); if (o instanceof JSON) { jsonToHTML((JSON) o, sb); } else { sb.append(o); } sb.append("</td></tr>\n"); } sb.append("</table>\n"); } else if (json instanceof JSONObject) { JSONObject jo = (JSONObject) json; Set<?> set = jo.entrySet(); Iterator<Map.Entry<?, ?>> itor = (Iterator<Entry<?, ?>>) set.iterator(); sb.append("<table border=\"1\">\n"); while (itor.hasNext()) { Map.Entry<?, ?> me = itor.next(); sb.append("<tr><td>\n"); sb.append(StringEscapeUtils.escapeHtml(me.getKey().toString())); sb.append("</td>\n"); sb.append("<td>\n"); if (me.getValue() instanceof JSON) { jsonToHTML((JSON) me.getValue(), sb); } else { sb.append(StringEscapeUtils.escapeHtml(me.getValue().toString())); } sb.append("</td></tr>\n"); } sb.append("</table>\n"); } }