Methods Summary |
---|
public boolean | containsKey(java.lang.String key)Returns true if this JSONObject contains the requested named key.
return valueMap.containsKey(key);
|
public JSONValue | get(java.lang.String key)Return null if not found.
return (JSONValue) valueMap.get(key);
|
public java.lang.String[] | getKeys()Returns keys for which this JSONObject has associations.
Set keySet = valueMap.keySet();
String[] keys = new String[keySet.size()];
Iterator iter = keySet.iterator();
int i = 0;
while (iter.hasNext()) {
keys[i++] = (String) iter.next();
}
return keys;
|
public com.oreilly.ajax.client.JSONObject | isObject()
return this;
|
public JSONValue | put(java.lang.String key, JSONValue jsonValue)Adds the named key and value pair to this JSONObject. If there was already
a value associated with that key, then the previous value is returned.
return (JSONValue) valueMap.put(key, jsonValue);
|
public java.lang.String | toString()Converts a JSONObject into a JSON representation that can be used to
communicate with a JSON service.
Set entrySet = valueMap.entrySet();
Iterator iter = entrySet.iterator();
StringBuffer sb = new StringBuffer();
sb.append("{");
while (iter.hasNext()) {
Entry entry = (Entry) iter.next();
sb.append("\"");
sb.append(entry.getKey().toString());
sb.append("\":");
sb.append(entry.getValue().toString());
if (iter.hasNext()) {
sb.append(",");
}
}
sb.append("}");
return sb.toString();
|