We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents d9b8507 + 2e0a813 commit 4cb1ae8Copy full SHA for 4cb1ae8
JSONObject.java
@@ -231,7 +231,21 @@ public JSONObject(JSONTokener x) throws JSONException {
231
if (c != ':') {
232
throw x.syntaxError("Expected a ':' after a key");
233
}
234
- this.putOnce(key, x.nextValue());
+
235
+ // Use syntaxError(..) to include error location
236
237
+ if (key != null) {
238
+ // Check if key exists
239
+ if (this.opt(key) != null) {
240
+ // key already exists
241
+ throw x.syntaxError("Duplicate key \"" + key + "\"");
242
+ }
243
+ // Only add value if non-null
244
+ Object value = x.nextValue();
245
+ if (value!=null) {
246
+ this.put(key, value);
247
248
249
250
// Pairs are separated by ','.
251
0 commit comments