Methods Summary |
---|
private org.json.JSONStringer | append(java.lang.String s)Append a value.
if (s == null) {
throw new JSONException("Null pointer");
}
if (this.mode == 'o" || this.mode == 'a") {
if (this.comma && this.mode == 'a") {
this.sb.append(',");
}
this.sb.append(s);
if (this.mode == 'o") {
this.mode = 'k";
}
this.comma = true;
return this;
}
throw new JSONException("Value out of sequence.");
|
public org.json.JSONStringer | array()Begin appending a new array. All values until the balancing
endArray will be appended to this array. The
endArray method must be called to mark the array's end.
if (this.mode == 'i" || this.mode == 'o" || this.mode == 'a") {
push('a");
this.append("[");
this.comma = false;
return this;
}
throw new JSONException("Misplaced array.");
|
private org.json.JSONStringer | end(char m, char c)End something.
if (this.mode != m) {
throw new JSONException(m == 'o" ? "Misplaced endObject." :
"Misplaced endArray.");
}
pop(m);
this.sb.append(c);
this.comma = true;
return this;
|
public org.json.JSONStringer | endArray()End an array. This method most be called to balance calls to
array .
return end('a", ']");
|
public org.json.JSONStringer | endObject()End an object. This method most be called to balance calls to
object .
return end('k", '}");
|
public org.json.JSONStringer | key(java.lang.String s)Append a key. The key will be associated with the next value. In an
object, every value must be preceded by a key.
if (s == null) {
throw new JSONException("Null key.");
}
if (this.mode == 'k") {
if (this.comma) {
this.sb.append(',");
}
this.sb.append(JSONObject.quote(s));
this.sb.append(':");
this.comma = false;
this.mode = 'o";
return this;
}
throw new JSONException("Misplaced key.");
|
public org.json.JSONStringer | object()Begin appending a new object. All keys and values until the balancing
endObject will be appended to this object. The
endObject method must be called to mark the object's end.
if (this.mode == 'i") {
this.mode = 'o";
}
if (this.mode == 'o" || this.mode == 'a") {
this.append("{");
push('k");
this.comma = false;
return this;
}
throw new JSONException("Misplaced object.");
|
private void | pop(char c)Pop an array or object scope.
if (this.top <= 0 || this.stack[this.top - 1] != c) {
throw new JSONException("Nesting error.");
}
this.top -= 1;
this.mode = this.top == 0 ? 'd" : this.stack[this.top - 1];
|
private void | push(char c)Push an array or object scope.
if (this.top >= maxdepth) {
throw new JSONException("Nesting too deep.");
}
this.stack[this.top] = c;
this.mode = c;
this.top += 1;
|
public java.lang.String | toString()Return the JSON text. This method is used to obtain the product of the
JSONStringer instance. It will return null if there was a
problem in the construction of the JSON text (such as the calls to
array were not properly balanced with calls to
endArray ).
return this.mode == 'd" ? this.sb.toString() : null;
|
public org.json.JSONStringer | value(boolean b)Append either the value true or the value
false .
return this.append(b ? "true" : "false");
|
public org.json.JSONStringer | value(double d)Append a double value.
return this.value(new Double(d));
|
public org.json.JSONStringer | value(long l)Append a long value.
return this.append(Long.toString(l));
|
public org.json.JSONStringer | value(java.lang.Object o)Append an object value.
if (JSONObject.NULL.equals(o)) {
return this.append("null");
}
if (o instanceof Number) {
JSONObject.testValidity(o);
return this.append(JSONObject.numberToString((Number)o));
}
if (o instanceof Boolean ||
o instanceof JSONArray || o instanceof JSONObject) {
return this.append(o.toString());
}
return this.append(JSONObject.quote(o.toString()));
|