/** * Get an optional int value associated with a key, or the default if there is * no such key or if the value is not a number. If the value is a string, an * attempt will be made to evaluate it as a number. * * @param key * A key string. * @param defaultValue * The default. * @return An object which is the value. */ public int optInt(String key, int defaultValue) { try { return getInt(key); } catch (Exception e) { return defaultValue; } }
/** * Get an optional int value associated with a key, or the default if there is * no such key or if the value is not a number. If the value is a string, an * attempt will be made to evaluate it as a number. * * @param key * A key string. * @param defaultValue * The default. * @return An object which is the value. */ public int optInt(String key, int defaultValue) { try { return getInt(key); } catch (Exception e) { return defaultValue; } }
/** * Get 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. */ public int getInt(Enum<?> key) throws JSONException { return getInt(key.name()); }
/** * Get 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. */ public int getInt(Enum<?> key) throws JSONException { return getInt(key.name()); }
System.out.println(" foo: " + j.getJSONArray("foo")); System.out.println(" op: " + j.getString("op")); System.out.println(" ten: " + j.getInt("ten")); System.out.println(" oops: " + j.optBoolean("oops")); System.out.println("int " + j.getInt("int")); System.out.println("long " + j.getInt("long")); System.out.println("longer " + j.getInt("longer"));
System.out.println(" foo: " + j.getJSONArray("foo")); System.out.println(" op: " + j.getString("op")); System.out.println(" ten: " + j.getInt("ten")); System.out.println(" oops: " + j.optBoolean("oops")); System.out.println("int " + j.getInt("int")); System.out.println("long " + j.getInt("long")); System.out.println("longer " + j.getInt("longer"));