/** * Get the boolean value associated with a key.<p> * * @param key A key string * @return the truth * @throws 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.<p> * * @param key a key string * @return the numeric value * @throws 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 double value associated with a key.<p> * * @param key a key string * @return the numeric value * @throws 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 boolean value associated with a key.<p> * * @param key A key string * @return the truth * @throws 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."); }
sb.append(quote(o.toString())); sb.append(':'); sb.append(valueToString(this.m_map.get(o)));
/** * Get the value object associated with a key.<p> * * @param key a key string * @return the object associated with the key * @throws 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; }
sb.append(quote(o.toString())); sb.append(':'); sb.append(valueToString(m_map.get(o)));
/** * Get the value object associated with a key.<p> * * @param key a key string * @return the object associated with the key * @throws 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.<p> * * @param key a key string * @return a JSONArray which is the value * @throws 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."); }
/** * Get the JSONObject value associated with a key.<p> * * @param key a key string * @return a JSONObject which is the value * @throws 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."); }
/** * Get the JSONArray value associated with a key.<p> * * @param key a key string * @return a JSONArray which is the value * @throws 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."); }
/** * Get the JSONObject value associated with a key.<p> * * @param key a key string * @return a JSONObject which is the value * @throws 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."); }
/** * Append a key. The key will be associated with the next value. In an * object, every value must be preceded by a key.<p> * * @param s a key string * @return this * @throws 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 (m_mode == 'k') { try { if (m_comma) { m_writer.write(','); } m_writer.write(JSONObject.quote(s)); m_writer.write(':'); m_comma = false; m_mode = 'o'; return this; } catch (IOException e) { throw new JSONException(e); } } throw new JSONException("Misplaced key."); }
/** * Append a key. The key will be associated with the next value. In an * object, every value must be preceded by a key.<p> * * @param s a key string * @return this * @throws 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.m_mode == 'k') { try { if (this.m_comma) { this.m_writer.write(','); } this.m_writer.write(JSONObject.quote(s)); this.m_writer.write(':'); this.m_comma = false; this.m_mode = 'o'; return this; } catch (IOException e) { throw new JSONException(e); } } throw new JSONException("Misplaced key."); }
writer.write(quote(k.toString())); writer.write(':'); Object v = m_map.get(k);
writer.write(quote(k.toString())); writer.write(':'); Object v = this.m_map.get(k);
return new JSONArray(value).toString(indentFactor, indent); return quote(value.toString());
return new JSONArray(value).toString(indentFactor, indent); return quote(value.toString());
return new JSONArray(value).toString(); return quote(value.toString());