/** * 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 string associated with an index.<p> * * @param index the index must be between 0 and length() - 1 * @return a string value * @throws JSONException if there is no value for the index */ public String getString(int index) throws JSONException { return get(index).toString(); }
/** * Get the string associated with an index.<p> * * @param index the index must be between 0 and length() - 1 * @return a string value * @throws JSONException if there is no value for the index */ public String getString(int index) throws JSONException { return get(index).toString(); }
/** * 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 JSONArray associated with an index.<p> * * @param index the index must be between 0 and length() - 1 * @return a JSONArray value * @throws JSONException if there is no value for the index or if the value is not a JSONArray */ public JSONArray getJSONArray(int index) throws JSONException { Object o = get(index); if (o instanceof JSONArray) { return (JSONArray)o; } throw new JSONException("JSONArray[" + index + "] is not a JSONArray."); }
/** * 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 double 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 double getDouble(int index) throws JSONException { Object o = get(index); try { return o instanceof Number ? ((Number)o).doubleValue() : Double.valueOf((String)o).doubleValue(); } catch (Exception e) { throw new JSONException("JSONArray[" + index + "] is not a number."); } }
/** * 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 double 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 double getDouble(int index) throws JSONException { Object o = get(index); try { return o instanceof Number ? ((Number)o).doubleValue() : Double.valueOf((String)o).doubleValue(); } catch (Exception e) { throw new JSONException("JSONArray[" + index + "] is not a number."); } }
/** * Get the JSONObject associated with an index.<p> * * @param index the index must be between 0 and length() - 1 * @return a JSONObject value * @throws JSONException if there is no value for the index or if the value is not a JSONObject */ public JSONObject getJSONObject(int index) throws JSONException { Object o = get(index); if (o instanceof JSONObject) { return (JSONObject)o; } throw new JSONException("JSONArray[" + index + "] is not a JSONObject."); }
/** * Get the JSONArray associated with an index.<p> * * @param index the index must be between 0 and length() - 1 * @return a JSONArray value * @throws JSONException if there is no value for the index or if the value is not a JSONArray */ public JSONArray getJSONArray(int index) throws JSONException { Object o = get(index); if (o instanceof JSONArray) { return (JSONArray)o; } throw new JSONException("JSONArray[" + index + "] is not a JSONArray."); }
/** * Get the JSONObject associated with an index.<p> * * @param index the index must be between 0 and length() - 1 * @return a JSONObject value * @throws JSONException if there is no value for the index or if the value is not a JSONObject */ public JSONObject getJSONObject(int index) throws JSONException { Object o = get(index); if (o instanceof JSONObject) { return (JSONObject)o; } throw new JSONException("JSONArray[" + index + "] is not a JSONObject."); }
/** * Get the boolean value associated with an index.<p> * * The string values "true" and "false" are converted to boolean.<p> * * @param index the index must be between 0 and length() - 1 * @return the truth * @throws JSONException if there is no value for the index or if the value is not convertable to boolean */ public boolean getBoolean(int index) throws JSONException { Object o = get(index); if (o.equals(Boolean.FALSE) || (o instanceof String && ((String)o).equalsIgnoreCase("false"))) { return false; } else if (o.equals(Boolean.TRUE) || (o instanceof String && ((String)o).equalsIgnoreCase("true"))) { return true; } throw new JSONException("JSONArray[" + index + "] is not a Boolean."); }
/** * Get the boolean value associated with an index.<p> * * The string values "true" and "false" are converted to boolean.<p> * * @param index the index must be between 0 and length() - 1 * @return the truth * @throws JSONException if there is no value for the index or if the value is not convertable to boolean */ public boolean getBoolean(int index) throws JSONException { Object o = get(index); if (o.equals(Boolean.FALSE) || ((o instanceof String) && ((String)o).equalsIgnoreCase("false"))) { return false; } else if (o.equals(Boolean.TRUE) || ((o instanceof String) && ((String)o).equalsIgnoreCase("true"))) { return true; } throw new JSONException("JSONArray[" + index + "] is not a Boolean."); }
JSONArray jsonLanguages = json.getJSONArray(JSON_LANGUAGES); for (int i = 0; i < jsonLanguages.length(); i++) { JSONObject jsonLang = (JSONObject)jsonLanguages.get(i); for (int i = 0; i < jsonAttachments.length(); i++) { try { JSONObject jsonAttachment = (JSONObject)jsonAttachments.get(i); JSONArray jsonAttLanguages = jsonAttachment.getJSONArray(JSON_LANGUAGES); for (int j = 0; j < jsonAttLanguages.length(); j++) { JSONObject jsonAttLanguage = (JSONObject)jsonAttLanguages.get(j);