/** * Get the long value associated with a key.<p> * * If the number value is too long for a long, it will be clipped.<p> * * @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 */ public long getLong(String key) throws JSONException { Object o = get(key); return o instanceof Number ? ((Number)o).longValue() : (long)getDouble(key); }
/** * Get the string associated with a key.<p> * * @param key a key string * @return a string which is the value * @throws JSONException if the key is not found */ public String getString(String key) throws JSONException { return get(key).toString(); }
/** * Merges the current JSON object with the given one, modifying the this.<p> * * @param jo the JSON object to merge * @param overwrite if to overwrite values * @param deep if to recurse in object values * * @throws JSONException if a value is a non-finite number * * @since 7.6 */ public void merge(JSONObject jo, boolean overwrite, boolean deep) throws JSONException { Iterator<String> it = jo.keys(); while (it.hasNext()) { String key = it.next(); if (!has(key)) { put(key, jo.get(key)); continue; } boolean recurse = deep && (jo.optJSONObject(key) != null) && (optJSONObject(key) != null); if (overwrite && !recurse) { put(key, jo.get(key)); continue; } if (recurse) { getJSONObject(key).merge(jo.getJSONObject(key), overwrite, deep); } } }
/** * Get the int value associated with a key.<p> * * If the number value is too large for an int, it will be clipped.<p> * * @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 */ public int getInt(String key) throws JSONException { Object o = get(key); return o instanceof Number ? ((Number)o).intValue() : (int)getDouble(key); }
/** * Get the string associated with a key.<p> * * @param key a key string * @return a string which is the value * @throws JSONException if the key is not found */ public String getString(String key) throws JSONException { return get(key).toString(); }
/** * Get the long value associated with a key.<p> * * If the number value is too long for a long, it will be clipped.<p> * * @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 */ public long getLong(String key) throws JSONException { Object o = get(key); return o instanceof Number ? ((Number)o).longValue() : (long)getDouble(key); }
/** * Get the boolean value associated with a key.<p> * * @param key A key string * @return the truth * @throws JSONException if the value is not a Boolean or the String "true" or "false" */ public boolean getBoolean(String key) throws JSONException { Object o = get(key); 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("JSONObject[" + quote(key) + "] is not a Boolean."); }
/** * Get the int value associated with a key.<p> * * If the number value is too large for an int, it will be clipped.<p> * * @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 */ public int getInt(String key) throws JSONException { Object o = get(key); return o instanceof Number ? ((Number)o).intValue() : (int)getDouble(key); }
/** * Get the double value associated with a key.<p> * * @param key a key string * @return the numeric value * @throws JSONException if the key is not found or * if the value is not a Number object and cannot be converted to a number */ public double getDouble(String key) throws JSONException { Object o = get(key); try { return o instanceof Number ? ((Number)o).doubleValue() : Double.valueOf((String)o).doubleValue(); } catch (Exception e) { throw new JSONException("JSONObject[" + quote(key) + "] is not a number."); } }
/** * Get the double value associated with a key.<p> * * @param key a key string * @return the numeric value * @throws JSONException if the key is not found or * if the value is not a Number object and cannot be converted to a number */ public double getDouble(String key) throws JSONException { Object o = get(key); try { return o instanceof Number ? ((Number)o).doubleValue() : Double.valueOf((String)o).doubleValue(); } catch (Exception e) { throw new JSONException("JSONObject[" + quote(key) + "] is not a number."); } }
/** * Get the boolean value associated with a key.<p> * * @param key A key string * @return the truth * @throws JSONException if the value is not a Boolean or the String "true" or "false" */ public boolean getBoolean(String key) throws JSONException { Object o = get(key); 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("JSONObject[" + quote(key) + "] is not a Boolean."); }
/** * Get the JSONArray value associated with a key.<p> * * @param key a key string * @return a JSONArray which is the value * @throws JSONException if the key is not found or * if the value is not a JSONArray */ public JSONArray getJSONArray(String key) throws JSONException { Object o = get(key); if (o instanceof JSONArray) { return (JSONArray)o; } throw new JSONException("JSONObject[" + quote(key) + "] is not a JSONArray."); }
/** * Get the JSONObject value associated with a key.<p> * * @param key a key string * @return a JSONObject which is the value * @throws JSONException if the key is not found or * if the value is not a JSONObject */ public JSONObject getJSONObject(String key) throws JSONException { Object o = get(key); if (o instanceof JSONObject) { return (JSONObject)o; } throw new JSONException("JSONObject[" + quote(key) + "] is not a JSONObject."); }
/** * Get the JSONArray value associated with a key.<p> * * @param key a key string * @return a JSONArray which is the value * @throws JSONException if the key is not found or * if the value is not a JSONArray */ public JSONArray getJSONArray(String key) throws JSONException { Object o = get(key); if (o instanceof JSONArray) { return (JSONArray)o; } throw new JSONException("JSONObject[" + quote(key) + "] is not a JSONArray."); }
/** * Get the JSONObject value associated with a key.<p> * * @param key a key string * @return a JSONObject which is the value * @throws JSONException if the key is not found or * if the value is not a JSONObject */ public JSONObject getJSONObject(String key) throws JSONException { Object o = get(key); if (o instanceof JSONObject) { return (JSONObject)o; } throw new JSONException("JSONObject[" + quote(key) + "] is not a JSONObject."); }
while (keys.hasNext()) { k = keys.next().toString(); v = jo.get(k).toString(); b.append(' '); b.append(k);
while (keys.hasNext()) { k = keys.next().toString(); v = jo.get(k).toString(); b.append(' '); b.append(k);
while (keys.hasNext()) { k = keys.next(); v = jo.get(k); if (v instanceof String) { s = (String)v;
while (keys.hasNext()) { k = keys.next().toString(); v = jo.get(k); if (v instanceof String) { s = (String)v;