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:
parent
d9b8507e6a
commit
7fed023080
1 changed files with 15 additions and 1 deletions
|
@ -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 ','.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue