/** * Gets a JSON object member of a JSON object. * * @param o The JSON object. Must not be {@code null}. * @param key The JSON object member key. Must not be {@code null}. * * @return The JSON object member value, may be {@code null}. * * @throws ParseException If the value is not of the expected type. */ public static JSONObject getJSONObject(final JSONObject o, final String key) throws ParseException { return getGeneric(o, key, JSONObject.class); }
/** * Gets a string member of a JSON object. * * @param o The JSON object. Must not be {@code null}. * @param key The JSON object member key. Must not be {@code null}. * * @return The JSON object member value, may be {@code null}. * * @throws ParseException If the value is not of the expected type. */ public static String getString(final JSONObject o, final String key) throws ParseException { return getGeneric(o, key, String.class); }
/** * Gets a JSON array member of a JSON object. * * @param o The JSON object. Must not be {@code null}. * @param key The JSON object member key. Must not be {@code null}. * * @return The JSON object member value, may be {@code null}. * * @throws ParseException If the value is not of the expected type. */ public static JSONArray getJSONArray(final JSONObject o, final String key) throws ParseException { return getGeneric(o, key, JSONArray.class); }
/** * Gets a boolean member of a JSON object. * * @param o The JSON object. Must not be {@code null}. * @param key The JSON object member key. Must not be {@code null}. * * @return The JSON object member value. * * @throws ParseException If the member is missing, the value is * {@code null} or not of the expected type. */ public static boolean getBoolean(final JSONObject o, final String key) throws ParseException { Boolean value = getGeneric(o, key, Boolean.class); if (value == null) { throw new ParseException("JSON object member with key \"" + key + "\" is missing or null", 0); } return value; }
/** * Gets a number member of a JSON object as {@code double}. * * @param o The JSON object. Must not be {@code null}. * @param key The JSON object member key. Must not be {@code null}. * * @return The JSON object member value, may be {@code null}. * * @throws ParseException If the member is missing, the value is * {@code null} or not of the expected type. */ public static double getDouble(final JSONObject o, final String key) throws ParseException { Number value = getGeneric(o, key, Number.class); if (value == null) { throw new ParseException("JSON object member with key \"" + key + "\" is missing or null", 0); } return value.doubleValue(); }
/** * Gets an number member of a JSON object as {@code int}. * * @param o The JSON object. Must not be {@code null}. * @param key The JSON object member key. Must not be {@code null}. * * @return The JSON object member value. * * @throws ParseException If the member is missing, the value is * {@code null} or not of the expected type. */ public static int getInt(final JSONObject o, final String key) throws ParseException { Number value = getGeneric(o, key, Number.class); if (value == null) { throw new ParseException("JSON object member with key \"" + key + "\" is missing or null", 0); } return value.intValue(); }
/** * Gets a number member of a JSON object as {@code long}. * * @param o The JSON object. Must not be {@code null}. * @param key The JSON object member key. Must not be {@code null}. * * @return The JSON object member value. * * @throws ParseException If the member is missing, the value is * {@code null} or not of the expected type. */ public static long getLong(final JSONObject o, final String key) throws ParseException { Number value = getGeneric(o, key, Number.class); if (value == null) { throw new ParseException("JSON object member with key \"" + key + "\" is missing or null", 0); } return value.longValue(); }
/** * Gets a number member of a JSON object {@code float}. * * @param o The JSON object. Must not be {@code null}. * @param key The JSON object member key. Must not be {@code null}. * * @return The JSON object member value, may be {@code null}. * * @throws ParseException If the member is missing, the value is * {@code null} or not of the expected type. */ public static float getFloat(final JSONObject o, final String key) throws ParseException { Number value = getGeneric(o, key, Number.class); if (value == null) { throw new ParseException("JSON object member with key \"" + key + "\" is missing or null", 0); } return value.floatValue(); }