public String prettyPrint(JSONObject jo, Options opt) throws JSONException {
int n = jo.length();
if (n == 0) {
return "{}";
}
final JSONArray children = new JSONArray();
Iterator<String> keys = jo.keys();
StringBuilder sb = new StringBuilder("{");
int newindent = opt.initialIndent + opt.indent;
String o;
if (n == 1) {
o = keys.next();
final Object v = jo.get(o);
if(!skipChildObject(children, opt, o, v)) {
sb.append(quote(o));
sb.append(": ");
sb.append(valueToString(v, opt));
}
} else {
while (keys.hasNext()) {
o = keys.next();
final Object v = jo.get(o);
if(skipChildObject(children, opt, o, v)) {
continue;
}
if (sb.length() > 1) {
sb.append(",\n");
} else {
sb.append('\n');
}
indent(sb, newindent);
sb.append(quote(o.toString()));
sb.append(": ");
sb.append(valueToString(v,
options().withIndent(opt.indent).withInitialIndent(newindent)));
}
if (sb.length() > 1) {
sb.append('\n');
indent(sb, newindent);
}
}
/** Render children if any were skipped (in "children in arrays" mode) */
if(children.length() > 0) {
if (sb.length() > 1) {
sb.append(",\n");
} else {
sb.append('\n');
}