mirror of
https://github.com/ethauvin/JSON-java.git
synced 2025-06-17 07:50:52 -07:00
Merge pull request #360 from migueltt/tokener-fix
Creating a JSONObject from a string that contains a duplicate key (any level) throws a JSONException that includes location
This commit is contained in:
commit
4cb1ae802a
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());
|
||||
|
||||
// Use syntaxError(..) to include error location
|
||||
|
||||
if (key != null) {
|
||||
// Check if key exists
|
||||
if (this.opt(key) != null) {
|
||||
// key already exists
|
||||
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