Simplify the check for object keys that are themselves objects.

For object keys, we can just skip the part of `nextValue()` that parses values
that are objects or arrays. Then the existing logic for unquoted values will
already stop at `{` or `[`, and that will produce a `Missing value` exception.
This commit is contained in:
Éamonn McManus 2023-09-27 12:42:04 -07:00
parent 661114c50d
commit 16967f322e
2 changed files with 2 additions and 6 deletions

View File

@ -428,10 +428,6 @@ public class JSONTokener {
case '"': case '"':
case '\'': case '\'':
return this.nextString(c); return this.nextString(c);
case '{':
throw syntaxError("Nested object not expected here.");
case '[':
throw syntaxError("Nested array not expected here.");
} }
/* /*

View File

@ -2230,7 +2230,7 @@ public class JSONObjectTest {
assertNull("Expected an exception",new JSONObject(str)); assertNull("Expected an exception",new JSONObject(str));
} catch (JSONException e) { } catch (JSONException e) {
assertEquals("Expecting an exception message", assertEquals("Expecting an exception message",
"Nested object not expected here. at 2 [character 3 line 1]", "Missing value at 1 [character 2 line 1]",
e.getMessage()); e.getMessage());
} }
try { try {
@ -2239,7 +2239,7 @@ public class JSONObjectTest {
assertNull("Expected an exception",new JSONObject(str)); assertNull("Expected an exception",new JSONObject(str));
} catch (JSONException e) { } catch (JSONException e) {
assertEquals("Expecting an exception message", assertEquals("Expecting an exception message",
"Nested array not expected here. at 10 [character 11 line 1]", "Missing value at 9 [character 10 line 1]",
e.getMessage()); e.getMessage());
} }
try { try {