1
0
Fork 0
mirror of https://github.com/ethauvin/JSON-java.git synced 2025-06-17 07:50:52 -07:00
This commit is contained in:
Douglas Crockford 2011-11-14 13:02:43 -08:00
parent df6190f3fc
commit 9bb970c6bc

View file

@ -54,10 +54,10 @@ SOFTWARE.
* <p> * <p>
* This can sometimes be easier than using a JSONObject to build a string. * This can sometimes be easier than using a JSONObject to build a string.
* @author JSON.org * @author JSON.org
* @version 2010-12-24 * @version 2011-11-14
*/ */
public class JSONWriter { public class JSONWriter {
private static final int maxdepth = 20; private static final int maxdepth = 200;
/** /**
* The comma flag determines if a comma should be output before the next * The comma flag determines if a comma should be output before the next
@ -78,7 +78,7 @@ public class JSONWriter {
/** /**
* The object/array stack. * The object/array stack.
*/ */
private JSONObject stack[]; private final JSONObject stack[];
/** /**
* The stack top index. A value of 0 indicates that the stack is empty. * The stack top index. A value of 0 indicates that the stack is empty.
@ -157,7 +157,7 @@ public class JSONWriter {
*/ */
private JSONWriter end(char mode, char c) throws JSONException { private JSONWriter end(char mode, char c) throws JSONException {
if (this.mode != mode) { if (this.mode != mode) {
throw new JSONException(mode == 'a' ? "Misplaced endArray." : throw new JSONException(mode == 'a' ? "Misplaced endArray." :
"Misplaced endObject."); "Misplaced endObject.");
} }
this.pop(mode); this.pop(mode);
@ -204,7 +204,7 @@ public class JSONWriter {
} }
if (this.mode == 'k') { if (this.mode == 'k') {
try { try {
stack[top - 1].putOnce(string, Boolean.TRUE); this.stack[this.top - 1].putOnce(string, Boolean.TRUE);
if (this.comma) { if (this.comma) {
this.writer.write(','); this.writer.write(',');
} }
@ -259,7 +259,7 @@ public class JSONWriter {
throw new JSONException("Nesting error."); throw new JSONException("Nesting error.");
} }
this.top -= 1; this.top -= 1;
this.mode = this.top == 0 ? this.mode = this.top == 0 ?
'd' : this.stack[this.top - 1] == null ? 'a' : 'k'; 'd' : this.stack[this.top - 1] == null ? 'a' : 'k';
} }