java.lang.Object
JSONObject object = ... String json = object.toString();
Stringers only encode well-formed JSON strings. In particular:
This class provides no facility for pretty-printing (ie. indenting) output. To encode indented output, use {@link JSONObject#toString(int)} or {@link JSONArray#toString(int)}.
Some implementations of the API support at most 20 levels of nesting. Attempts to create more than 20 levels of nesting may fail with a JSONException.
Each stringer may be used to encode a single top level value. Instances of this class are not thread safe. Although this class is nonfinal, it was not designed for inheritance and should not be subclassed. In particular, self-use by overrideable methods is not specified. See Effective Java Item 17, "Design and Document or inheritance or else prohibit it" for further information.
public JSONStringer()
Begins encoding a new array. Each call to this method must be paired with a call to {@link #endArray}.
public org.json.JSONStringer array() throws org.json.JSONException
Ends encoding the current array.
public org.json.JSONStringer endArray() throws org.json.JSONException
Begins encoding a new object. Each call to this method must be paired with a call to {@link #endObject}.
public org.json.JSONStringer object() throws org.json.JSONException
Ends encoding the current object.
public org.json.JSONStringer endObject() throws org.json.JSONException
Encodes {@code value}.
public org.json.JSONStringer value(Object value) throws org.json.JSONException
Encodes {@code value} to this stringer.
public org.json.JSONStringer value(boolean value) throws org.json.JSONException
Encodes {@code value} to this stringer.
public org.json.JSONStringer value(double value) throws org.json.JSONException
Encodes {@code value} to this stringer.
public org.json.JSONStringer value(long value) throws org.json.JSONException
Encodes the key (property name) to this stringer.
public org.json.JSONStringer key(String name) throws org.json.JSONException
Returns the encoded JSON string.
If invoked with unterminated arrays or unclosed objects, this method's return value is undefined.
Warning: although it contradicts the general contract of {@link Object#toString}, this method returns null if the stringer contains no data.
public java.lang.String toString()
From Class | Methods |
---|---|
java.lang.Object | getClass, hashCode, equals, clone, toString, notify, notifyAll, wait, wait, wait, finalize |