/** * Get the double value associated with a key. * @param key A key string. * @return The numeric value. * @throws RuntimeException 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) { Object object = this.get(key); try { return object instanceof Number ? ((Number)object).doubleValue() : Double.parseDouble((String)object); } catch (Exception e) { throw new RuntimeException("JSONObject[" + quote(key) + "] is not a number."); } }
/** * Get the double value associated with a key. * @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) { Object object = this.get(key); try { return object instanceof Number ? ((Number)object).doubleValue() : Double.parseDouble((String)object); } catch (Exception e) { throw new RuntimeException("JSONObject[" + quote(key) + "] is not a number."); } }
/** * Get the long value associated with a key. * * @param key A key string. * @return The long value. * @throws JSONException if the key is not found or if the value cannot * be converted to a long. */ public long getLong(String key) { Object object = this.get(key); try { return object instanceof Number ? ((Number)object).longValue() : Long.parseLong((String)object); } catch (Exception e) { throw new RuntimeException("JSONObject[" + quote(key) + "] is not a long.", e); } }
/** * Get the long value associated with a key. * * @param key A key string. * @return The long value. * @throws RuntimeException if the key is not found or if the value cannot * be converted to a long. */ public long getLong(String key) { Object object = this.get(key); try { return object instanceof Number ? ((Number)object).longValue() : Long.parseLong((String)object); } catch (Exception e) { throw new RuntimeException("JSONObject[" + quote(key) + "] is not a long.", e); } }
/** * Get the JSONObject value associated with a key. * * @webref jsonobject:method * @brief Gets the JSONObject value associated with a key * @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. * @see JSONObject#getJSONArray(String) * @see JSONObject#setJSONObject(String, JSONObject) * @see JSONObject#setJSONArray(String, JSONArray) */ public JSONObject getJSONObject(String key) { Object object = this.get(key); if (object instanceof JSONObject) { return (JSONObject)object; } throw new RuntimeException("JSONObject[" + quote(key) + "] is not a JSONObject."); }
/** * Get the JSONArray value associated with a key. * * @webref jsonobject:method * @brief Gets the JSONArray value associated with a key * @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. * @see JSONObject#getJSONObject(String) * @see JSONObject#setJSONObject(String, JSONObject) * @see JSONObject#setJSONArray(String, JSONArray) */ public JSONArray getJSONArray(String key) { Object object = this.get(key); if (object instanceof JSONArray) { return (JSONArray)object; } throw new RuntimeException("JSONObject[" + quote(key) + "] is not a JSONArray."); }
/** * Gets the String associated with a key * * @webref jsonobject:method * @brief Gets the string value associated with a key * @param key a key string * @return A string which is the value. * @throws JSONException if there is no string value for the key. * @see JSONObject#getInt(String) * @see JSONObject#getFloat(String) * @see JSONObject#getBoolean(String) */ public String getString(String key) { Object object = this.get(key); if (object instanceof String) { return (String)object; } throw new RuntimeException("JSONObject[" + quote(key) + "] not a string."); }
/** * Get the JSONObject value associated with a key. * * @webref jsonobject:method * @brief Gets the JSONObject value associated with a key * @param key a key string * @return A JSONObject which is the value or null if not available. * @throws RuntimeException if the value is not a JSONObject. * @see JSONObject#getJSONArray(String) * @see JSONObject#setJSONObject(String, JSONObject) * @see JSONObject#setJSONArray(String, JSONArray) */ public JSONObject getJSONObject(String key) { Object object = this.get(key); if (object == null) { return null; } if (object instanceof JSONObject) { return (JSONObject)object; } throw new RuntimeException("JSONObject[" + quote(key) + "] is not a JSONObject."); }
/** * Get the JSONArray value associated with a key. * * @webref jsonobject:method * @brief Gets the JSONArray value associated with a key * @param key a key string * @return A JSONArray which is the value, or null if not present * @throws RuntimeException if the value is not a JSONArray. * @see JSONObject#getJSONObject(String) * @see JSONObject#setJSONObject(String, JSONObject) * @see JSONObject#setJSONArray(String, JSONArray) */ public JSONArray getJSONArray(String key) { Object object = this.get(key); if (object == null) { return null; } if (object instanceof JSONArray) { return (JSONArray)object; } throw new RuntimeException("JSONObject[" + quote(key) + "] is not a JSONArray."); }
/** * Gets the String associated with a key * * @webref jsonobject:method * @brief Gets the string value associated with a key * @param key a key string * @return A string which is the value. * @throws RuntimeException if there is no string value for the key. * @see JSONObject#getInt(String) * @see JSONObject#getFloat(String) * @see JSONObject#getBoolean(String) */ public String getString(String key) { Object object = this.get(key); if (object == null) { // Adding for rev 0257 in line with other p5 api return null; } if (object instanceof String) { return (String)object; } throw new RuntimeException("JSONObject[" + quote(key) + "] is not a string"); }
/** * Gets the int value associated with a key * * @webref jsonobject:method * @brief Gets the int value associated with a key * @param key a key string * @return The integer value. * @throws JSONException if the key is not found or if the value cannot * be converted to an integer. * @see JSONObject#getFloat(String) * @see JSONObject#getString(String) * @see JSONObject#getBoolean(String) */ public int getInt(String key) { Object object = this.get(key); try { return object instanceof Number ? ((Number)object).intValue() : Integer.parseInt((String)object); } catch (Exception e) { throw new RuntimeException("JSONObject[" + quote(key) + "] is not an int."); } }
/** * Get the boolean value associated with a key. * * @webref jsonobject:method * @brief Gets the boolean value associated with a key * @param key a key string * @return The truth. * @throws RuntimeException if the value is not a Boolean or the String "true" or "false". * @see JSONObject#getInt(String) * @see JSONObject#getFloat(String) * @see JSONObject#getString(String) */ public boolean getBoolean(String key) { Object object = this.get(key); if (object.equals(Boolean.FALSE) || (object instanceof String && ((String)object).equalsIgnoreCase("false"))) { return false; } else if (object.equals(Boolean.TRUE) || (object instanceof String && ((String)object).equalsIgnoreCase("true"))) { return true; } throw new RuntimeException("JSONObject[" + quote(key) + "] is not a Boolean."); }
/** * Get the boolean value associated with a key. * * @webref jsonobject:method * @brief Gets the boolean value associated with a key * @param key a key string * @return The truth. * @throws JSONException if the value is not a Boolean or the String "true" or "false". * @see JSONObject#getInt(String) * @see JSONObject#getFloat(String) * @see JSONObject#getString(String) */ public boolean getBoolean(String key) { Object object = this.get(key); if (object.equals(Boolean.FALSE) || (object instanceof String && ((String)object).equalsIgnoreCase("false"))) { return false; } else if (object.equals(Boolean.TRUE) || (object instanceof String && ((String)object).equalsIgnoreCase("true"))) { return true; } throw new RuntimeException("JSONObject[" + quote(key) + "] is not a Boolean."); }
/** * Gets the int value associated with a key * * @webref jsonobject:method * @brief Gets the int value associated with a key * @param key A key string. * @return The integer value. * @throws RuntimeException if the key is not found or if the value cannot * be converted to an integer. * @see JSONObject#getFloat(String) * @see JSONObject#getString(String) * @see JSONObject#getBoolean(String) */ public int getInt(String key) { Object object = this.get(key); if (object == null) { throw new RuntimeException("JSONObject[" + quote(key) + "] not found"); } try { return object instanceof Number ? ((Number)object).intValue() : Integer.parseInt((String)object); } catch (Exception e) { throw new RuntimeException("JSONObject[" + quote(key) + "] is not an int."); } }