/** * Get the optional double value associated with an index.<p> * * The defaultValue is returned if there is no value for the index, * or if the value is not a number and cannot be converted to a number.<p> * * @param index the index must be between 0 and length() - 1 * @param defaultValue the default value * @return the value */ public double optDouble(int index, double defaultValue) { try { return getDouble(index); } catch (Exception e) { return defaultValue; } }
/** * Get the optional double value associated with an index.<p> * * The defaultValue is returned if there is no value for the index, * or if the value is not a number and cannot be converted to a number.<p> * * @param index the index must be between 0 and length() - 1 * @param defaultValue the default value * @return the value */ public double optDouble(int index, double defaultValue) { try { return getDouble(index); } catch (Exception e) { return defaultValue; } }
/** * Get the int value associated with an index.<p> * * @param index the index must be between 0 and length() - 1 * @return the value * @throws JSONException if the key is not found or if the value cannot be converted to a number */ public int getInt(int index) throws JSONException { Object o = get(index); return o instanceof Number ? ((Number)o).intValue() : (int)getDouble(index); }
/** * Get the long value associated with an index.<p> * * @param index the index must be between 0 and length() - 1 * @return the value * @throws JSONException if the key is not found or if the value cannot be converted to a number */ public long getLong(int index) throws JSONException { Object o = get(index); return o instanceof Number ? ((Number)o).longValue() : (long)getDouble(index); }
/** * Get the int value associated with an index.<p> * * @param index the index must be between 0 and length() - 1 * @return the value * @throws JSONException if the key is not found or if the value cannot be converted to a number */ public int getInt(int index) throws JSONException { Object o = get(index); return o instanceof Number ? ((Number)o).intValue() : (int)getDouble(index); }
/** * Get the long value associated with an index.<p> * * @param index the index must be between 0 and length() - 1 * @return the value * @throws JSONException if the key is not found or if the value cannot be converted to a number */ public long getLong(int index) throws JSONException { Object o = get(index); return o instanceof Number ? ((Number)o).longValue() : (long)getDouble(index); }