/** * Pop an array or object scope.<p> * * @param c the scope to close * @throws JSONException zf nesting is wrong */ private void pop(char c) throws JSONException { if ((m_top <= 0) || (m_stack[m_top - 1] != c)) { throw new JSONException("Nesting error."); } m_top -= 1; m_mode = m_top == 0 ? 'd' : m_stack[m_top - 1]; }
/** * Pop an array or object scope.<p> * * @param c the scope to close * @throws JSONException zf nesting is wrong */ private void pop(char c) throws JSONException { if (this.m_top <= 0 || this.m_stack[this.m_top - 1] != c) { throw new JSONException("Nesting error."); } this.m_top -= 1; this.m_mode = this.m_top == 0 ? 'd' : this.m_stack[this.m_top - 1]; }
/** * Push an array or object scope.<p> * * @param c the scope to open * @throws JSONException if nesting is too deep */ private void push(char c) throws JSONException { if (m_top >= MAXDEPTH) { throw new JSONException("Nesting too deep."); } m_stack[m_top] = c; m_mode = c; m_top += 1; } }
/** * Push an array or object scope.<p> * * @param c the scope to open * @throws JSONException if nesting is too deep */ private void push(char c) throws JSONException { if (this.m_top >= MAXDEPTH) { throw new JSONException("Nesting too deep."); } this.m_stack[this.m_top] = c; this.m_mode = c; this.m_top += 1; } }
/** * Make a JSONException to signal a syntax error.<p> * * @param message the error message * @return a JSONException object, suitable for throwing */ public JSONException syntaxError(String message) { return new JSONException(message + toString()); }
/** * Make a JSONException to signal a syntax error.<p> * * @param message the error message * @return a JSONException object, suitable for throwing */ public JSONException syntaxError(String message) { return new JSONException(message + toString()); }
/** * 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 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 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 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 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 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 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 value object associated with a key.<p> * * @param key a key string * @return the object associated with the key * @throws JSONException if the key is not found */ public Object get(String key) throws JSONException { Object o = opt(key); if (o == null) { throw new JSONException("JSONObject[" + quote(key) + "] not found."); } return o; }
/** * Get the value object associated with a key.<p> * * @param key a key string * @return the object associated with the key * @throws JSONException if the key is not found */ public Object get(String key) throws JSONException { Object o = opt(key); if (o == null) { throw new JSONException("JSONObject[" + quote(key) + "] not found."); } return o; }
/** * 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."); }