1
0
Fork 0
mirror of https://github.com/ethauvin/JSON-java.git synced 2025-06-17 07:50:52 -07: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:
Miguel 2017-08-10 19:05:57 -04:00
parent 7fed023080
commit 7d8353401a

View file

@ -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