1
0
Fork 0
mirror of https://github.com/ethauvin/JSON-java.git synced 2025-06-17 07:50:52 -07:00

Update to include error location when creating JSONObject from string/text

This commit is contained in:
Miguel 2017-08-09 21:52:36 -04:00
parent d9b8507e6a
commit 7fed023080

View file

@ -231,7 +231,21 @@ public class JSONObject {
if (c != ':') {
throw x.syntaxError("Expected a ':' after a key");
}
this.putOnce(key, x.nextValue());
// Replace: this.putOnce(key, x.nextValue());
// Use syntaxError(..) to include error location
if (key != null) {
// Check if key exists
if (this.opt(key) != null) {
throw x.syntaxError("Duplicate key \"" + key + "\"");
}
// Only add value if non-null
Object value = x.nextValue();
if (value!=null) {
this.put(key, value);
}
}
// Pairs are separated by ','.