@@ -83,11 +83,22 @@ public JSONArray() {
83
83
* If there is a syntax error.
84
84
*/
85
85
public JSONArray (JSONTokener x ) throws JSONException {
86
+ this (x , new JSONParserConfiguration ());
87
+ }
88
+
89
+ /**
90
+ * Constructs a JSONArray from a JSONTokener and a JSONParserConfiguration.
91
+ *
92
+ * @param x A JSONTokener instance from which the JSONArray is constructed.
93
+ * @param jsonParserConfiguration A JSONParserConfiguration instance that controls the behavior of the parser.
94
+ * @throws JSONException If a syntax error occurs during the construction of the JSONArray.
95
+ */
96
+ public JSONArray (JSONTokener x , JSONParserConfiguration jsonParserConfiguration ) throws JSONException {
86
97
this ();
87
98
if (x .nextClean () != '[' ) {
88
99
throw x .syntaxError ("A JSONArray text must start with '['" );
89
100
}
90
-
101
+
91
102
char nextChar = x .nextClean ();
92
103
if (nextChar == 0 ) {
93
104
// array is unclosed. No ']' found, instead EOF
@@ -104,27 +115,28 @@ public JSONArray(JSONTokener x) throws JSONException {
104
115
this .myArrayList .add (x .nextValue ());
105
116
}
106
117
switch (x .nextClean ()) {
107
- case 0 :
108
- // array is unclosed. No ']' found, instead EOF
109
- throw x .syntaxError ("Expected a ',' or ']'" );
110
- case ',' :
111
- nextChar = x .nextClean ();
112
- if (nextChar == 0 ) {
118
+ case 0 :
113
119
// array is unclosed. No ']' found, instead EOF
114
120
throw x .syntaxError ("Expected a ',' or ']'" );
115
- }
116
- if (nextChar == ']' ) {
121
+ case ',' :
122
+ nextChar = x .nextClean ();
123
+ if (nextChar == 0 ) {
124
+ // array is unclosed. No ']' found, instead EOF
125
+ throw x .syntaxError ("Expected a ',' or ']'" );
126
+ }
127
+ if (nextChar == ']' ) {
128
+ return ;
129
+ }
130
+ x .back ();
131
+ break ;
132
+ case ']' :
117
133
return ;
118
- }
119
- x .back ();
120
- break ;
121
- case ']' :
122
- return ;
123
- default :
124
- throw x .syntaxError ("Expected a ',' or ']'" );
134
+ default :
135
+ throw x .syntaxError ("Expected a ',' or ']'" );
125
136
}
126
137
}
127
138
}
139
+
128
140
}
129
141
130
142
/**
@@ -138,7 +150,22 @@ public JSONArray(JSONTokener x) throws JSONException {
138
150
* If there is a syntax error.
139
151
*/
140
152
public JSONArray (String source ) throws JSONException {
141
- this (new JSONTokener (source ));
153
+ this (source , new JSONParserConfiguration ());
154
+ }
155
+
156
+ /**
157
+ * Construct a JSONArray from a source JSON text.
158
+ *
159
+ * @param source
160
+ * A string that begins with <code>[</code> <small>(left
161
+ * bracket)</small> and ends with <code>]</code>
162
+ * <small>(right bracket)</small>.
163
+ * @param jsonParserConfiguration the parser config object
164
+ * @throws JSONException
165
+ * If there is a syntax error.
166
+ */
167
+ public JSONArray (String source , JSONParserConfiguration jsonParserConfiguration ) throws JSONException {
168
+ this (new JSONTokener (source ), jsonParserConfiguration );
142
169
}
143
170
144
171
/**
0 commit comments