class JsonWriter
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private int |
indent_ |
private java.lang.String |
spc_ |
Constructor and Description |
---|
JsonWriter()
Constructor with default properties.
|
JsonWriter(int indent,
boolean spacer)
Custom constructor.
|
Modifier and Type | Method and Description |
---|---|
private java.lang.String |
getIndent(int level)
Returns prepended whitespace.
|
private java.lang.String |
getIntroIndent(int level,
char chr,
boolean isPositioned)
Returns prepended whitespace containing an opener character.
|
static void |
main(java.lang.String[] args) |
java.lang.String |
toJson(java.lang.Object item)
Converts a SAMP data item to JSON.
|
private void |
toJson(java.lang.StringBuffer sbuf,
java.lang.Object item,
int level,
boolean isPositioned)
Recursive method which does the work for conversion.
|
public JsonWriter()
public JsonWriter(int indent, boolean spacer)
indent
- number of characters indent per levelspacer
- whether to put spaces inside bracketspublic java.lang.String toJson(java.lang.Object item)
item
- SAMP-friendly objectprivate void toJson(java.lang.StringBuffer sbuf, java.lang.Object item, int level, boolean isPositioned)
isPositioned=false
.sbuf
- string buffer to append result toitem
- object to convertlevel
- current indentation levelisPositioned
- true if output should be direct to sbuf,
false if it needs a newline plus indentation firstprivate java.lang.String getIntroIndent(int level, char chr, boolean isPositioned)
level
- indentation levelchr
- opener characterisPositioned
- true if output should be direct to sbuf,
false if it needs a newline plus indentation firstprivate java.lang.String getIndent(int level)
level
- indentation levelpublic static void main(java.lang.String[] args)