mirror of
https://github.com/fankes/JSON-java-compat.git
synced 2025-09-06 18:55:30 +08:00
Adding JSONTokener.back() just before throwing JSONException
This forces JSONTokener.syntaxError(..) to point to the last character of the duplicate key.
This commit is contained in:
@@ -232,12 +232,13 @@ public class JSONObject {
|
|||||||
throw x.syntaxError("Expected a ':' after a key");
|
throw x.syntaxError("Expected a ':' after a key");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace: this.putOnce(key, x.nextValue());
|
|
||||||
// Use syntaxError(..) to include error location
|
// Use syntaxError(..) to include error location
|
||||||
|
|
||||||
if (key != null) {
|
if (key != null) {
|
||||||
// Check if key exists
|
// Check if key exists
|
||||||
if (this.opt(key) != null) {
|
if (this.opt(key) != null) {
|
||||||
|
// back one token to point to the last key character
|
||||||
|
x.back();
|
||||||
throw x.syntaxError("Duplicate key \"" + key + "\"");
|
throw x.syntaxError("Duplicate key \"" + key + "\"");
|
||||||
}
|
}
|
||||||
// Only add value if non-null
|
// Only add value if non-null
|
||||||
|
Reference in New Issue
Block a user