/** * Get the boolean value associated with a key. * * @param key A key string. * @return The truth. * @throws com.restfb.json.JsonException if the value is not a Boolean or the String "true" or "false". */ public boolean getBoolean(String key) throws JsonException { Object o = get(key); if (o.equals(Boolean.FALSE) || (o instanceof String && ((String) o).equalsIgnoreCase("false"))) { return false; } else if (o.equals(Boolean.TRUE) || (o instanceof String && ((String) o).equalsIgnoreCase("true"))) { return true; } throw new JsonException("JsonObject[" + quote(key) + "] is not a Boolean."); }
/** * Get the double value associated with a key. * * @param key A key string. * @return The numeric value. * @throws com.restfb.json.JsonException if the key is not found or if the value is not a Number object * and cannot be converted to a number. */ public double getDouble(String key) throws JsonException { Object o = get(key); try { return o instanceof Number ? ((Number) o).doubleValue() : Double.valueOf((String) o).doubleValue(); } catch (Exception e) { throw new JsonException("JsonObject[" + quote(key) + "] is not a number."); } }
/** * Get the value object associated with a key. * * @param key A key string. * @return The object associated with the key. * @throws com.restfb.json.JsonException if the key is not found. */ public Object get(String key) throws JsonException { Object o = opt(key); if (o == null) { throw new JsonException("JsonObject[" + quote(key) + "] not found."); } return o; }
/** * Get the JsonArray value associated with a key. * * @param key A key string. * @return A JsonArray which is the value. * @throws com.restfb.json.JsonException if the key is not found or if the value is not a JsonArray. */ public JsonArray getJsonArray(String key) throws JsonException { Object o = get(key); if (o instanceof JsonArray) { return (JsonArray) o; } throw new JsonException("JsonObject[" + quote(key) + "] is not a JsonArray."); }
sb.append(quote(o.toString())); sb.append(':'); sb.append(valueToString(this.map.get(o)));
/** * Get the JsonObject value associated with a key. * * @param key A key string. * @return A JsonObject which is the value. * @throws com.restfb.json.JsonException if the key is not found or if the value is not a JsonObject. */ public JsonObject getJsonObject(String key) throws JsonException { Object o = get(key); if (o instanceof JsonObject) { return (JsonObject) o; } throw new JsonException("JsonObject[" + quote(key) + "] is not a JsonObject."); }
writer.write(quote(k.toString())); writer.write(':'); Object v = this.map.get(k);
/** * Append a key. The key will be associated with the next value. In an object, * every value must be preceded by a key. * * @param s A key string. * @return this * @throws com.restfb.json.JsonException If the key is out of place. For example, keys do not belong in * arrays or if the key is null. */ public JsonWriter key(String s) throws JsonException { if (s == null) { throw new JsonException("Null key."); } if (this.mode == 'k') { try { stack[top - 1].putOnce(s, Boolean.TRUE); if (this.comma) { this.writer.write(','); } this.writer.write(JsonObject.quote(s)); this.writer.write(':'); this.comma = false; this.mode = 'o'; return this; } catch (IOException e) { throw new JsonException(e); } } throw new JsonException("Misplaced key."); }
return new JsonArray(value).toString(indentFactor, indent); return quote(value.toString());
return new JsonArray(value).toString(); return quote(value.toString());