@@ -83,11 +83,22 @@ public JSONArray() {
8383 * If there is a syntax error.
8484 */
8585 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 {
8697 this ();
8798 if (x .nextClean () != '[' ) {
8899 throw x .syntaxError ("A JSONArray text must start with '['" );
89100 }
90-
101+
91102 char nextChar = x .nextClean ();
92103 if (nextChar == 0 ) {
93104 // array is unclosed. No ']' found, instead EOF
@@ -104,27 +115,28 @@ public JSONArray(JSONTokener x) throws JSONException {
104115 this .myArrayList .add (x .nextValue ());
105116 }
106117 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 :
113119 // array is unclosed. No ']' found, instead EOF
114120 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 ']' :
117133 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 ']'" );
125136 }
126137 }
127138 }
139+
128140 }
129141
130142 /**
@@ -138,7 +150,22 @@ public JSONArray(JSONTokener x) throws JSONException {
138150 * If there is a syntax error.
139151 */
140152 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 );
142169 }
143170
144171 /**
0 commit comments