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.
(String key)
| 510 | * be converted to an integer. |
| 511 | */ |
| 512 | public int getInt(String key) throws JSONException { |
| 513 | Object object = get(key); |
| 514 | try { |
| 515 | return object instanceof Number ? |
| 516 | ((Number)object).intValue() : |
| 517 | Integer.parseInt((String)object); |
| 518 | } catch (Exception e) { |
| 519 | throw new JSONException("JSONObject[" + quote(key) + |
| 520 | "] is not an int."); |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | |
| 525 | /** |