We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d9b8507 commit 7fed023Copy full SHA for 7fed023
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
+ // Replace: this.putOnce(key, x.nextValue());
236
+ // Use syntaxError(..) to include error location
237
238
+ if (key != null) {
239
+ // Check if key exists
240
+ if (this.opt(key) != null) {
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