/** * Returns the set of properties defined on this JSONObject. The returned set * is immutable. */ public Set<String> keySet() { final String[] keys = computeKeys(); return new AbstractSet<String>() { @Override public boolean contains(Object o) { return (o instanceof String) && containsKey((String) o); } @Override public Iterator<String> iterator() { return Arrays.asList(keys).iterator(); } @Override public int size() { return keys.length; } }; }
/** * Returns the set of properties defined on this JSONObject. The returned set * is immutable. */ public Set<String> keySet() { final String[] keys = computeKeys(); return new AbstractSet<String>() { @Override public boolean contains(Object o) { return (o instanceof String) && containsKey((String) o); } @Override public Iterator<String> iterator() { return Arrays.asList(keys).iterator(); } @Override public int size() { return keys.length; } }; }
/** * Converts a JSONObject into a JSON representation that can be used to * communicate with a JSON service. * * @return a JSON string representation of this JSONObject instance */ @Override public String toString() { StringBuilder sb = new StringBuilder("{"); boolean first = true; String[] keys = computeKeys(); for (String key : keys) { if (first) { first = false; } else { sb.append(", "); } sb.append(JsonUtils.escapeValue(key)); sb.append(":"); sb.append(get(key)); } sb.append("}"); return sb.toString(); }
/** * Converts a JSONObject into a JSON representation that can be used to * communicate with a JSON service. * * @return a JSON string representation of this JSONObject instance */ @Override public String toString() { StringBuilder sb = new StringBuilder("{"); boolean first = true; String[] keys = computeKeys(); for (String key : keys) { if (first) { first = false; } else { sb.append(", "); } sb.append(JsonUtils.escapeValue(key)); sb.append(":"); sb.append(get(key)); } sb.append("}"); return sb.toString(); }