/** * Produce a JSONArray of JSONObjects from a comma delimited text string, * using the first row as a source of names. * @param string The comma delimited text. * @return A JSONArray of JSONObjects. * @throws JSONException */ public static JSONArray toJSONArray(String string) throws JSONException { return toJSONArray(new JSONTokener(string)); }
/** * Make a JSONException to signal a syntax error. * * @param message The error message. * @return A JSONException object, suitable for throwing */ public JSONException syntaxError(String message) { return new JSONException(message + toString()); }
/** * Append an object value. * @param o The object to append. It can be null, or a Boolean, Number, * String, JSONObject, or JSONArray, or an object with a toJSONString() * method. * @return this * @throws JSONException If the value is out of sequence. */ public JSONWriter value(Object o) throws JSONException { return this.append(JSONObject.valueToString(o)); } }
/** * Put a value in the JSONArray, where the value will be a JSONObject which is * produced from a Map. * * @param value * A Map value. * @return this. */ public JSONArray put(Map<?, ?> value) { put(new JSONObject(value)); return this; }
/** * Produce a JSONArray of JSONObjects from a comma delimited text string, * using the first row as a source of names. * @param x The JSONTokener containing the comma delimited text. * @return A JSONArray of JSONObjects. * @throws JSONException */ public static JSONArray toJSONArray(JSONTokener x) throws JSONException { return toJSONArray(rowToJSONArray(x), x); }
/** * Get an optional double associated with a key, or NaN if there is no such * key or if its value is not a number. If the value is a string, an attempt * will be made to evaluate it as a number. * * @param key * A string which is the key. * @return An object which is the value. */ public double optDouble(String key) { return optDouble(key, Double.NaN); }
/** * Get an optional string associated with a key. It returns an empty string if * there is no such key. If the value is not a string and is not null, then it * is coverted to a string. * * @param key * A key string. * @return A string which is the value. */ public String optString(String key) { return optString(key, ""); }
/** * End an object. This method most be called to balance calls to * <code>object</code>. * @return this * @throws JSONException If incorrectly nested. */ public JSONWriter endObject() throws JSONException { return this.end('k', '}'); }
/** * Convert a JSONObject into a well-formed, element-normal XML string. * @param o A JSONObject. * @return A string. * @throws JSONException */ public static String toString(Object o) throws JSONException { return toString(o, null); }
/** * Append a boolean value. This increases the array's length by one. * * @param value * A boolean value. * @return this. */ public JSONArray put(boolean value) { put(value ? Boolean.TRUE : Boolean.FALSE); return this; }
/** * Put a value in the JSONArray, where the value will be a JSONObject which is * produced from a Map. * * @param value * A Map value. * @return this. */ public JSONArray put(Map<?, ?> value) { put(new JSONObject(value)); return this; }
/** * Produce a JSONArray of JSONObjects from a comma delimited text string, * using the first row as a source of names. * @param string The comma delimited text. * @return A JSONArray of JSONObjects. * @throws JSONException */ public static JSONArray toJSONArray(String string) throws JSONException { return toJSONArray(new JSONTokener(string)); }
/** * Make a JSONException to signal a syntax error. * * @param message The error message. * @return A JSONException object, suitable for throwing */ public JSONException syntaxError(String message) { return new JSONException(message + toString()); }
/** * Append an object value. * @param o The object to append. It can be null, or a Boolean, Number, * String, JSONObject, or JSONArray, or an object with a toJSONString() * method. * @return this * @throws JSONException If the value is out of sequence. */ public JSONWriter value(Object o) throws JSONException { return this.append(JSONObject.valueToString(o)); } }
/** * Produce a JSONArray of JSONObjects from a comma delimited text string, * using the first row as a source of names. * @param x The JSONTokener containing the comma delimited text. * @return A JSONArray of JSONObjects. * @throws JSONException */ public static JSONArray toJSONArray(JSONTokener x) throws JSONException { return toJSONArray(rowToJSONArray(x), x); }
/** * End an array. This method most be called to balance calls to * <code>array</code>. * @return this * @throws JSONException If incorrectly nested. */ public JSONWriter endArray() throws JSONException { return this.end('a', ']'); }
/** * Convert a JSONObject into a well-formed, element-normal XML string. * @param o A JSONObject. * @return A string. * @throws JSONException */ public static String toString(Object o) throws JSONException { return toString(o, null); }
/** * Produce a JSONArray of JSONObjects from a comma delimited text string * using a supplied JSONArray as the source of element names. * @param names A JSONArray of strings. * @param string The comma delimited text. * @return A JSONArray of JSONObjects. * @throws JSONException */ public static JSONArray toJSONArray(JSONArray names, String string) throws JSONException { return toJSONArray(names, new JSONTokener(string)); }
/** * Produce a JSONArray of JSONObjects from a comma delimited text string * using a supplied JSONArray as the source of element names. * @param names A JSONArray of strings. * @param string The comma delimited text. * @return A JSONArray of JSONObjects. * @throws JSONException */ public static JSONArray toJSONArray(JSONArray names, String string) throws JSONException { return toJSONArray(names, new JSONTokener(string)); }