/** * Get the optional JSONArray associated with an index.<p> * * @param index the index must be between 0 and length() - 1 * @return aA JSONArray value, or null if the index has no value, or if the value is not a JSONArray */ public JSONArray optJSONArray(int index) { Object o = opt(index); return o instanceof JSONArray ? (JSONArray)o : null; }
/** * Get the optional JSONArray associated with an index.<p> * * @param index the index must be between 0 and length() - 1 * @return aA JSONArray value, or null if the index has no value, or if the value is not a JSONArray */ public JSONArray optJSONArray(int index) { Object o = opt(index); return o instanceof JSONArray ? (JSONArray)o : null; }
/** * Get the optional JSONObject associated with an index.<p> * * Null is returned if the key is not found, or null if the index has * no value, or if the value is not a JSONObject.<p> * * @param index the index must be between 0 and length() - 1 * @return a JSONObject value */ public JSONObject optJSONObject(int index) { Object o = opt(index); return o instanceof JSONObject ? (JSONObject)o : null; }
/** * Get the optional JSONObject associated with an index.<p> * * Null is returned if the key is not found, or null if the index has * no value, or if the value is not a JSONObject.<p> * * @param index the index must be between 0 and length() - 1 * @return a JSONObject value */ public JSONObject optJSONObject(int index) { Object o = opt(index); return o instanceof JSONObject ? (JSONObject)o : null; }
/** * Determine if the value is null.<p> * * @param index the index must be between 0 and length() - 1 * @return true if the value at the index is null, or if there is no value */ public boolean isNull(int index) { return JSONObject.NULL.equals(opt(index)); }
/** * Get the optional string associated with an index.<p> * * The defaultValue is returned if the key is not found.<p> * * @param index tThe index must be between 0 and length() - 1 * @param defaultValue the default value * @return a String value */ public String optString(int index, String defaultValue) { Object o = opt(index); return o != null ? o.toString() : defaultValue; }
/** * Get the optional string associated with an index.<p> * * The defaultValue is returned if the key is not found.<p> * * @param index tThe index must be between 0 and length() - 1 * @param defaultValue the default value * @return a String value */ public String optString(int index, String defaultValue) { Object o = opt(index); return o != null ? o.toString() : defaultValue; }
/** * Determine if the value is null.<p> * * @param index the index must be between 0 and length() - 1 * @return true if the value at the index is null, or if there is no value */ public boolean isNull(int index) { return JSONObject.NULL.equals(opt(index)); }
/** * Get the object value associated with an index.<p> * * @param index the index must be between 0 and length() - 1 * @return an object value * @throws JSONException if there is no value for the index */ public Object get(int index) throws JSONException { Object o = opt(index); if (o == null) { throw new JSONException("JSONArray[" + index + "] not found."); } return o; }
/** * Get the object value associated with an index.<p> * * @param index the index must be between 0 and length() - 1 * @return an object value * @throws JSONException if there is no value for the index */ public Object get(int index) throws JSONException { Object o = opt(index); if (o == null) { throw new JSONException("JSONArray[" + index + "] not found."); } return o; }
sb.append(','); Object o = ja.opt(i); if (o != null) { String s = o.toString();
sb.append(','); Object o = ja.opt(i); if (o != null) { String s = o.toString();
final String word = words.opt(i).toString(); wordsToCheck.add(word);
o = ja.opt(1); if (o instanceof JSONObject) {
o = ja.opt(1); if (o instanceof JSONObject) {
len = ja.length(); for (i = 0; i < len; ++i) { b.append(toString(ja.opt(i), (tagName == null) ? "array" : tagName));
len = ja.length(); for (i = 0; i < len; ++i) { b.append(toString(ja.opt(i), (tagName == null) ? "array" : tagName));
/** * Produce a JSONObject by combining a JSONArray of names with the values * of this JSONArray.<p> * * @param names a JSONArray containing a list of key strings. These will be * paired with the values * @return a JSONObject, or null if there are no names or if this JSONArray * has no values * @throws JSONException if any of the names are null */ public JSONObject toJSONObject(JSONArray names) throws JSONException { if ((names == null) || (names.length() == 0) || (length() == 0)) { return null; } JSONObject jo = new JSONObject(); for (int i = 0; i < names.length(); i += 1) { jo.put(names.getString(i), opt(i)); } return jo; }
/** * Produce a JSONObject by combining a JSONArray of names with the values * of this JSONArray.<p> * * @param names a JSONArray containing a list of key strings. These will be * paired with the values * @return a JSONObject, or null if there are no names or if this JSONArray * has no values * @throws JSONException if any of the names are null */ public JSONObject toJSONObject(JSONArray names) throws JSONException { if (names == null || names.length() == 0 || length() == 0) { return null; } JSONObject jo = new JSONObject(); for (int i = 0; i < names.length(); i += 1) { jo.put(names.getString(i), this.opt(i)); } return jo; }