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
(String key)
| 606 | * @see JSONObject#getBoolean(String) |
| 607 | */ |
| 608 | public int getInt(String key) { |
| 609 | Object object = this.get(key); |
| 610 | if (object == null) { |
| 611 | throw new RuntimeException("JSONObject[" + quote(key) + "] not found"); |
| 612 | } |
| 613 | try { |
| 614 | return object instanceof Number ? |
| 615 | ((Number)object).intValue() : Integer.parseInt((String)object); |
| 616 | } catch (Exception e) { |
| 617 | throw new RuntimeException("JSONObject[" + quote(key) + "] is not an int."); |
| 618 | } |
| 619 | } |
| 620 | |
| 621 | |
| 622 | /** |