@@ -75,31 +75,19 @@ public JSONArray() {
75
75
}
76
76
77
77
/**
78
- * Constructs a JSONArray from a JSONTokener.
79
- * <p>
80
- * This constructor reads the JSONTokener to parse a JSON array. It uses the default JSONParserConfiguration.
78
+ * Construct a JSONArray from a JSONTokener.
81
79
*
82
- * @param x A JSONTokener
83
- * @throws JSONException If there is a syntax error.
80
+ * @param x
81
+ * A JSONTokener
82
+ * @throws JSONException
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
- * JSONParserConfiguration contains strictMode turned off (false) by default.
92
- *
93
- * @param x A JSONTokener instance from which the JSONArray is constructed.
94
- * @param jsonParserConfiguration A JSONParserConfiguration instance that controls the behavior of the parser.
95
- * @throws JSONException If a syntax error occurs during the construction of the JSONArray.
96
- */
97
- public JSONArray (JSONTokener x , JSONParserConfiguration jsonParserConfiguration ) throws JSONException {
98
86
this ();
99
87
if (x .nextClean () != '[' ) {
100
88
throw x .syntaxError ("A JSONArray text must start with '['" );
101
89
}
102
-
90
+
103
91
char nextChar = x .nextClean ();
104
92
if (nextChar == 0 ) {
105
93
// array is unclosed. No ']' found, instead EOF
@@ -113,34 +101,27 @@ public JSONArray(JSONTokener x, JSONParserConfiguration jsonParserConfiguration)
113
101
this .myArrayList .add (JSONObject .NULL );
114
102
} else {
115
103
x .back ();
116
- this .myArrayList .add (x .nextValue (jsonParserConfiguration ));
104
+ this .myArrayList .add (x .nextValue ());
117
105
}
118
106
switch (x .nextClean ()) {
119
- case 0 :
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 ) {
120
113
// array is unclosed. No ']' found, instead EOF
121
114
throw x .syntaxError ("Expected a ',' or ']'" );
122
- case ',' :
123
- nextChar = x .nextClean ();
124
- if (nextChar == 0 ) {
125
- // array is unclosed. No ']' found, instead EOF
126
- throw x .syntaxError ("Expected a ',' or ']'" );
127
- }
128
- if (nextChar == ']' ) {
129
- return ;
130
- }
131
- x .back ();
132
- break ;
133
- case ']' :
134
- if (jsonParserConfiguration .isStrictMode ()) {
135
- nextChar = x .nextClean ();
136
- if (nextChar != 0 ) {
137
- throw x .syntaxError ("invalid character found after end of array: " + nextChar );
138
- }
139
- }
140
-
115
+ }
116
+ if (nextChar == ']' ) {
141
117
return ;
142
- default :
143
- throw x .syntaxError ("Expected a ',' or ']'" );
118
+ }
119
+ x .back ();
120
+ break ;
121
+ case ']' :
122
+ return ;
123
+ default :
124
+ throw x .syntaxError ("Expected a ',' or ']'" );
144
125
}
145
126
}
146
127
}
@@ -157,19 +138,7 @@ public JSONArray(JSONTokener x, JSONParserConfiguration jsonParserConfiguration)
157
138
* If there is a syntax error.
158
139
*/
159
140
public JSONArray (String source ) throws JSONException {
160
- this (new JSONTokener (source ), new JSONParserConfiguration ());
161
- }
162
-
163
- /**
164
- * Constructs a JSONArray from a source JSON text and a JSONParserConfiguration.
165
- *
166
- * @param source A string that begins with <code>[</code> <small>(left bracket)</small> and
167
- * ends with <code>]</code> <small>(right bracket)</small>.
168
- * @param jsonParserConfiguration A JSONParserConfiguration instance that controls the behavior of the parser.
169
- * @throws JSONException If there is a syntax error.
170
- */
171
- public JSONArray (String source , JSONParserConfiguration jsonParserConfiguration ) throws JSONException {
172
- this (new JSONTokener (source ), jsonParserConfiguration );
141
+ this (new JSONTokener (source ));
173
142
}
174
143
175
144
/**
@@ -398,7 +367,7 @@ public Number getNumber(int index) throws JSONException {
398
367
399
368
/**
400
369
* Get the enum value associated with an index.
401
- *
370
+ *
402
371
* @param <E>
403
372
* Enum Type
404
373
* @param clazz
@@ -586,7 +555,7 @@ public String join(String separator) throws JSONException {
586
555
if (len == 0 ) {
587
556
return "" ;
588
557
}
589
-
558
+
590
559
StringBuilder sb = new StringBuilder (
591
560
JSONObject .valueToString (this .myArrayList .get (0 )));
592
561
@@ -900,7 +869,7 @@ public Integer optIntegerObject(int index, Integer defaultValue) {
900
869
901
870
/**
902
871
* Get the enum value associated with a key.
903
- *
872
+ *
904
873
* @param <E>
905
874
* Enum Type
906
875
* @param clazz
@@ -915,7 +884,7 @@ public <E extends Enum<E>> E optEnum(Class<E> clazz, int index) {
915
884
916
885
/**
917
886
* Get the enum value associated with a key.
918
- *
887
+ *
919
888
* @param <E>
920
889
* Enum Type
921
890
* @param clazz
@@ -948,8 +917,8 @@ public <E extends Enum<E>> E optEnum(Class<E> clazz, int index, E defaultValue)
948
917
}
949
918
950
919
/**
951
- * Get the optional BigInteger value associated with an index. The
952
- * defaultValue is returned if there is no value for the index, or if the
920
+ * Get the optional BigInteger value associated with an index. The
921
+ * defaultValue is returned if there is no value for the index, or if the
953
922
* value is not a number and cannot be converted to a number.
954
923
*
955
924
* @param index
@@ -964,8 +933,8 @@ public BigInteger optBigInteger(int index, BigInteger defaultValue) {
964
933
}
965
934
966
935
/**
967
- * Get the optional BigDecimal value associated with an index. The
968
- * defaultValue is returned if there is no value for the index, or if the
936
+ * Get the optional BigDecimal value associated with an index. The
937
+ * defaultValue is returned if there is no value for the index, or if the
969
938
* value is not a number and cannot be converted to a number. If the value
970
939
* is float or double, the {@link BigDecimal#BigDecimal(double)}
971
940
* constructor will be used. See notes on the constructor for conversion
@@ -1134,7 +1103,7 @@ public Number optNumber(int index, Number defaultValue) {
1134
1103
if (val instanceof Number ){
1135
1104
return (Number ) val ;
1136
1105
}
1137
-
1106
+
1138
1107
if (val instanceof String ) {
1139
1108
try {
1140
1109
return JSONObject .stringToNumber ((String ) val );
@@ -1211,7 +1180,7 @@ public JSONArray put(Collection<?> value) {
1211
1180
public JSONArray put (double value ) throws JSONException {
1212
1181
return this .put (Double .valueOf (value ));
1213
1182
}
1214
-
1183
+
1215
1184
/**
1216
1185
* Append a float value. This increases the array's length by one.
1217
1186
*
@@ -1466,19 +1435,19 @@ public JSONArray put(int index, Object value) throws JSONException {
1466
1435
*
1467
1436
* @param collection
1468
1437
* A Collection.
1469
- * @return this.
1438
+ * @return this.
1470
1439
*/
1471
1440
public JSONArray putAll (Collection <?> collection ) {
1472
1441
this .addAll (collection , false );
1473
1442
return this ;
1474
1443
}
1475
-
1444
+
1476
1445
/**
1477
1446
* Put an Iterable's elements in to the JSONArray.
1478
1447
*
1479
1448
* @param iter
1480
1449
* An Iterable.
1481
- * @return this.
1450
+ * @return this.
1482
1451
*/
1483
1452
public JSONArray putAll (Iterable <?> iter ) {
1484
1453
this .addAll (iter , false );
@@ -1490,7 +1459,7 @@ public JSONArray putAll(Iterable<?> iter) {
1490
1459
*
1491
1460
* @param array
1492
1461
* A JSONArray.
1493
- * @return this.
1462
+ * @return this.
1494
1463
*/
1495
1464
public JSONArray putAll (JSONArray array ) {
1496
1465
// directly copy the elements from the source array to this one
@@ -1505,7 +1474,7 @@ public JSONArray putAll(JSONArray array) {
1505
1474
* @param array
1506
1475
* Array. If the parameter passed is null, or not an array or Iterable, an
1507
1476
* exception will be thrown.
1508
- * @return this.
1477
+ * @return this.
1509
1478
*
1510
1479
* @throws JSONException
1511
1480
* If not an array, JSONArray, Iterable or if an value is non-finite number.
@@ -1516,17 +1485,17 @@ public JSONArray putAll(Object array) throws JSONException {
1516
1485
this .addAll (array , false );
1517
1486
return this ;
1518
1487
}
1519
-
1488
+
1520
1489
/**
1521
- * Creates a JSONPointer using an initialization string and tries to
1490
+ * Creates a JSONPointer using an initialization string and tries to
1522
1491
* match it to an item within this JSONArray. For example, given a
1523
1492
* JSONArray initialized with this document:
1524
1493
* <pre>
1525
1494
* [
1526
1495
* {"b":"c"}
1527
1496
* ]
1528
1497
* </pre>
1529
- * and this JSONPointer string:
1498
+ * and this JSONPointer string:
1530
1499
* <pre>
1531
1500
* "/0/b"
1532
1501
* </pre>
@@ -1539,17 +1508,17 @@ public JSONArray putAll(Object array) throws JSONException {
1539
1508
public Object query (String jsonPointer ) {
1540
1509
return query (new JSONPointer (jsonPointer ));
1541
1510
}
1542
-
1511
+
1543
1512
/**
1544
- * Uses a user initialized JSONPointer and tries to
1513
+ * Uses a user initialized JSONPointer and tries to
1545
1514
* match it to an item within this JSONArray. For example, given a
1546
1515
* JSONArray initialized with this document:
1547
1516
* <pre>
1548
1517
* [
1549
1518
* {"b":"c"}
1550
1519
* ]
1551
1520
* </pre>
1552
- * and this JSONPointer:
1521
+ * and this JSONPointer:
1553
1522
* <pre>
1554
1523
* "/0/b"
1555
1524
* </pre>
@@ -1562,23 +1531,23 @@ public Object query(String jsonPointer) {
1562
1531
public Object query (JSONPointer jsonPointer ) {
1563
1532
return jsonPointer .queryFrom (this );
1564
1533
}
1565
-
1534
+
1566
1535
/**
1567
1536
* Queries and returns a value from this object using {@code jsonPointer}, or
1568
1537
* returns null if the query fails due to a missing key.
1569
- *
1538
+ *
1570
1539
* @param jsonPointer the string representation of the JSON pointer
1571
1540
* @return the queried value or {@code null}
1572
1541
* @throws IllegalArgumentException if {@code jsonPointer} has invalid syntax
1573
1542
*/
1574
1543
public Object optQuery (String jsonPointer ) {
1575
1544
return optQuery (new JSONPointer (jsonPointer ));
1576
1545
}
1577
-
1546
+
1578
1547
/**
1579
1548
* Queries and returns a value from this object using {@code jsonPointer}, or
1580
1549
* returns null if the query fails due to a missing key.
1581
- *
1550
+ *
1582
1551
* @param jsonPointer The JSON pointer
1583
1552
* @return the queried value or {@code null}
1584
1553
* @throws IllegalArgumentException if {@code jsonPointer} has invalid syntax
@@ -1698,11 +1667,11 @@ public String toString() {
1698
1667
1699
1668
/**
1700
1669
* Make a pretty-printed JSON text of this JSONArray.
1701
- *
1670
+ *
1702
1671
* <p>If <pre> {@code indentFactor > 0}</pre> and the {@link JSONArray} has only
1703
1672
* one element, then the array will be output on a single line:
1704
1673
* <pre>{@code [1]}</pre>
1705
- *
1674
+ *
1706
1675
* <p>If an array has 2 or more elements, then it will be output across
1707
1676
* multiple lines: <pre>{@code
1708
1677
* [
@@ -1714,7 +1683,7 @@ public String toString() {
1714
1683
* <p><b>
1715
1684
* Warning: This method assumes that the data structure is acyclical.
1716
1685
* </b>
1717
- *
1686
+ *
1718
1687
* @param indentFactor
1719
1688
* The number of spaces to add to each level of indentation.
1720
1689
* @return a printable, displayable, transmittable representation of the
@@ -1748,11 +1717,11 @@ public Writer write(Writer writer) throws JSONException {
1748
1717
1749
1718
/**
1750
1719
* Write the contents of the JSONArray as JSON text to a writer.
1751
- *
1720
+ *
1752
1721
* <p>If <pre>{@code indentFactor > 0}</pre> and the {@link JSONArray} has only
1753
1722
* one element, then the array will be output on a single line:
1754
1723
* <pre>{@code [1]}</pre>
1755
- *
1724
+ *
1756
1725
* <p>If an array has 2 or more elements, then it will be output across
1757
1726
* multiple lines: <pre>{@code
1758
1727
* [
@@ -1978,7 +1947,7 @@ private void addAll(Object array, boolean wrap, int recursionDepth, JSONParserCo
1978
1947
"JSONArray initial value should be a string or collection or array." );
1979
1948
}
1980
1949
}
1981
-
1950
+
1982
1951
/**
1983
1952
* Create a new JSONException in a common format for incorrect conversions.
1984
1953
* @param idx index of the item
0 commit comments