Skip to content

Commit

Permalink
Support keywords as keys
Browse files Browse the repository at this point in the history
  • Loading branch information
wb9688 authored and TobiGr committed Jan 2, 2022
1 parent 3324e15 commit 93da2aa
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/main/java/com/grack/nanojson/JsonParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,18 @@ private int advanceTokenOld() throws JsonParserException {
JsonObject map = new JsonObject();
if (advanceToken() != JsonTokener.TOKEN_OBJECT_END)
while (true) {
if (token != JsonTokener.TOKEN_STRING && token != JsonTokener.TOKEN_SEMI_STRING)
switch (token) {
case JsonTokener.TOKEN_NULL:
case JsonTokener.TOKEN_TRUE:
case JsonTokener.TOKEN_FALSE:
value = value.toString();
break;
case JsonTokener.TOKEN_STRING:
case JsonTokener.TOKEN_SEMI_STRING:
break;
default:
throw tokener.createParseException(null, "Expected STRING, got " + token, true);
}
String key = (String)value;
if (token == JsonTokener.TOKEN_SEMI_STRING) {
if (advanceTokenOld() != JsonTokener.TOKEN_COLON)
Expand Down Expand Up @@ -265,8 +275,18 @@ private int advanceToken() throws JsonParserException {
JsonObject map = new JsonObject();
if (advanceToken() != JsonTokener.TOKEN_OBJECT_END)
while (true) {
if (token != JsonTokener.TOKEN_STRING && token != JsonTokener.TOKEN_SEMI_STRING)
switch (token) {
case JsonTokener.TOKEN_NULL:
case JsonTokener.TOKEN_TRUE:
case JsonTokener.TOKEN_FALSE:
value = value.toString();
break;
case JsonTokener.TOKEN_STRING:
case JsonTokener.TOKEN_SEMI_STRING:
break;
default:
throw tokener.createParseException(null, "Expected STRING, got " + token, true);
}
String key = (String)value;
if (token == JsonTokener.TOKEN_SEMI_STRING) {
if (advanceTokenOld() != JsonTokener.TOKEN_COLON)
Expand Down

0 comments on commit 93da2aa

Please sign in to comment.