diff --git a/JSONArray.java b/JSONArray.java index a402d6714..8775a1984 100644 --- a/JSONArray.java +++ b/JSONArray.java @@ -1230,7 +1230,7 @@ public Object optQuery(String jsonPointer) { * Queries and returns a value from this object using {@code jsonPointer}, or * returns null if the query fails due to a missing key. * - * @param The JSON pointer + * @param jsonPointer The JSON pointer * @return the queried value or {@code null} * @throws IllegalArgumentException if {@code jsonPointer} has invalid syntax */ @@ -1323,8 +1323,9 @@ public JSONObject toJSONObject(JSONArray names) throws JSONException { * whitespace is added. If it is not possible to produce a syntactically * correct JSON text then null will be returned instead. This could occur if * the array contains an invalid number. - *
+ *
* Warning: This method assumes that the data structure is acyclical. + * * * @return a printable, displayable, transmittable representation of the * array. @@ -1339,9 +1340,24 @@ public String toString() { } /** - * Make a pretty-printed JSON text of this JSONArray. Warning: This method - * assumes that the data structure is acyclical. - * + * Make a pretty-printed JSON text of this JSONArray. + * + *
If indentFactor > 0
and the {@link JSONArray} has only
+ * one element, then the array will be output on a single line:
+ *
{@code [1]}+ * + *
If an array has 2 or more elements, then it will be output across + * multiple lines:
{@code + * [ + * 1, + * "value 2", + * 3 + * ] + * }+ *
+ * Warning: This method assumes that the data structure is acyclical. + * + * * @param indentFactor * The number of spaces to add to each level of indentation. * @return a printable, displayable, transmittable representation of the @@ -1360,8 +1376,9 @@ public String toString(int indentFactor) throws JSONException { /** * Write the contents of the JSONArray as JSON text to a writer. For * compactness, no whitespace is added. - *
+ *
* Warning: This method assumes that the data structure is acyclical. + * * * @return The writer. * @throws JSONException @@ -1371,10 +1388,23 @@ public Writer write(Writer writer) throws JSONException { } /** - * Write the contents of the JSONArray as JSON text to a writer. For - * compactness, no whitespace is added. - *
+ * Write the contents of the JSONArray as JSON text to a writer. + * + *
If indentFactor > 0
and the {@link JSONArray} has only
+ * one element, then the array will be output on a single line:
+ *
{@code [1]}+ * + *
If an array has 2 or more elements, then it will be output across + * multiple lines:
{@code + * [ + * 1, + * "value 2", + * 3 + * ] + * }+ *
* Warning: This method assumes that the data structure is acyclical. + * * * @param writer * Writes the serialized JSON diff --git a/JSONObject.java b/JSONObject.java index 8ad7864df..46ed86942 100644 --- a/JSONObject.java +++ b/JSONObject.java @@ -1676,7 +1676,7 @@ public Object optQuery(String jsonPointer) { * Queries and returns a value from this object using {@code jsonPointer}, or * returns null if the query fails due to a missing key. * - * @param The JSON pointer + * @param jsonPointer The JSON pointer * @return the queried value or {@code null} * @throws IllegalArgumentException if {@code jsonPointer} has invalid syntax */ @@ -2002,9 +2002,10 @@ public JSONArray toJSONArray(JSONArray names) throws JSONException { * Make a JSON text of this JSONObject. For compactness, no whitespace is * added. If this would not result in a syntactically correct JSON text, * then null will be returned instead. - *
+ *
* Warning: This method assumes that the data structure is acyclical.
- *
+ *
+ *
* @return a printable, displayable, portable, transmittable representation
* of the object, beginning with {
(left
* brace) and ending with }
(right
@@ -2021,8 +2022,20 @@ public String toString() {
/**
* Make a pretty-printed JSON text of this JSONObject.
- *
+ * + *
If indentFactor > 0
and the {@link JSONObject}
+ * has only one key, then the object will be output on a single line:
+ *
{@code {"key": 1}}+ * + *
If an object has 2 or more keys, then it will be output across
+ * multiple lines:
+ * {
+ * "key1": 1,
+ * "key2": "value 2",
+ * "key3": 3
+ * }
* Warning: This method assumes that the data structure is acyclical. + * * * @param indentFactor * The number of spaces to add to each level of indentation. @@ -2172,9 +2185,10 @@ public static Object wrap(Object object) { /** * Write the contents of the JSONObject as JSON text to a writer. For * compactness, no whitespace is added. - *
+ *
* Warning: This method assumes that the data structure is acyclical. - * + * + * * @return The writer. * @throws JSONException */ @@ -2238,8 +2252,20 @@ static final void indent(Writer writer, int indent) throws IOException { /** * Write the contents of the JSONObject as JSON text to a writer. - *
+ * + *
If indentFactor > 0
and the {@link JSONObject}
+ * has only one key, then the object will be output on a single line:
+ *
{@code {"key": 1}}+ * + *
If an object has 2 or more keys, then it will be output across
+ * multiple lines:
+ * {
+ * "key1": 1,
+ * "key2": "value 2",
+ * "key3": 3
+ * }
* Warning: This method assumes that the data structure is acyclical. + * * * @param writer * Writes the serialized JSON