Get the long value associated with a key. @param key A key string. @return The long value. @throws JSONException if the key is not found or if the value cannot be converted to a long.
(String key)
| 567 | * be converted to a long. |
| 568 | */ |
| 569 | public long getLong(String key) throws JSONException { |
| 570 | Object object = get(key); |
| 571 | try { |
| 572 | return object instanceof Number ? |
| 573 | ((Number)object).longValue() : |
| 574 | Long.parseLong((String)object); |
| 575 | } catch (Exception e) { |
| 576 | throw new JSONException("JSONObject[" + quote(key) + |
| 577 | "] is not a long."); |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | |
| 582 | /** |