public class JSONRenderer extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
JSONRenderer.Options
Rendering options
|
| Constructor and Description |
|---|
JSONRenderer() |
| Modifier and Type | Method and Description |
|---|---|
String |
doubleToString(double d)
Produce a string from a double.
|
String |
join(JSONArray ja,
String separator)
Make a string from the contents of this JSONArray.
|
String |
numberToString(Number n)
Produce a string from a Number.
|
JSONRenderer.Options |
options()
Return an Options object with default values
|
String |
prettyPrint(JSONArray ja,
JSONRenderer.Options opt)
Pretty-print a JSONArray
|
String |
prettyPrint(JSONObject jo,
JSONRenderer.Options opt)
Make a prettyprinted JSON text of this JSONObject.
|
String |
quote(String string)
Quote the supplied string for JSON
|
void |
quote(Writer w,
String string)
Quote the supplied string for JSON, to the supplied Writer
|
void |
testNumberValidity(Object o)
Throw an exception if the object is an NaN or infinite number.
|
String |
toString(JSONArray ja)
Make a JSON text of the supplied JSONArray.
|
String |
toString(JSONObject jo)
Render the supplied JSONObject to a String, in
the simplest possible way.
|
String |
valueToString(Object value)
Make a JSON text of an Object value.
|
String |
valueToString(Object value,
JSONRenderer.Options opt)
Make a JSON String of an Object value, with rendering options
|
Writer |
write(Writer writer,
JSONArray ja)
Write the contents of the supplied JSONArray as JSON text to a writer.
|
Writer |
write(Writer writer,
JSONObject jo)
Write the contents of the supplied JSONObject as JSON text to a writer.
|
public JSONRenderer.Options options()
public String toString(JSONObject jo)
public String toString(JSONArray ja)
Warning: This method assumes that the data structure is acyclical.
public void quote(Writer w, String string) throws IOException
IOExceptionpublic String valueToString(Object value) throws JSONException
Warning: This method assumes that the data structure is acyclical.
value - The value to be serialized.{ (left brace) and ending
with } (right brace).JSONException - If the value is or contains an invalid number.public String valueToString(Object value, JSONRenderer.Options opt) throws JSONException
Warning: This method assumes that the data structure is acyclical.
value - The value to be serialized.indentFactor - The number of spaces to add to each level of
indentation.indent - The indentation of the top level.{ (left brace) and ending
with } (right brace).JSONException - If the object contains an invalid number.public String numberToString(Number n) throws JSONException
n - A NumberJSONException - If n is a non-finite number.public String prettyPrint(JSONObject jo, JSONRenderer.Options opt) throws JSONException
Warning: This method assumes that the data structure is acyclical.
indentFactor - The number of spaces to add to each level of
indentation.indent - The indentation of the top level.{ (left brace) and ending
with } (right brace).JSONException - If the object contains an invalid number.public String prettyPrint(JSONArray ja, JSONRenderer.Options opt) throws JSONException
JSONExceptionpublic void testNumberValidity(Object o) throws JSONException
o - The object to test.JSONException - If o is a non-finite number.public String join(JSONArray ja, String separator) throws JSONException
separator string is inserted between each element.
Warning: This method assumes that the data structure is acyclical.separator - A string that will be inserted between the elements.JSONException - If the array contains an invalid number.public Writer write(Writer writer, JSONObject jo) throws JSONException
Warning: This method assumes that the data structure is acyclical.
JSONExceptionpublic Writer write(Writer writer, JSONArray ja) throws JSONException
Warning: This method assumes that the data structure is acyclical.
JSONExceptionpublic String doubleToString(double d)
d - A double.Copyright © 2014 The Apache Software Foundation. All rights reserved.