JsonObject parseObject() throws JsonException {
final JsonObject object = jsonFactory.createObject();
int c = nextNonWhitespace();
if (c != '{') {
throw new JsonException(
"Payload does not begin with '{'. Got " + c + "("
+ Character.valueOf((char) c) + ")");
}
while (true) {
c = nextNonWhitespace();
switch (c) {
case '}':
// We're done.
return object;
case '"':
case '\'':
back(c);
// Ready to start a key.
final String key = nextString(c);
if (nextNonWhitespace() != ':') {
throw new JsonException(
"Invalid object: expecting \":\"");
}
// TODO(knorton): Make sure this key is not already set.
object.put(key, (JsonValue)nextValue());
switch (nextNonWhitespace()) {
case ',':
break;
case '}':
return object;
default:
throw new JsonException(
"Invalid object: expecting } or ,");
}
break;
case ',':
break;
default:
if (lenient && (Character.isDigit((char) c) || Character.isLetterOrDigit((char) c)))
{
StringBuilder keyBuffer = new StringBuilder();
keyBuffer.append(c);
while (true) {
c = next();
if (Character.isDigit((char) c) || Character.isLetterOrDigit((char) c)) {
keyBuffer.append(c);
} else {
back(c);
break;
}
}
if (nextNonWhitespace() != ':') {
throw new JsonException(
"Invalid object: expecting \":\"");
}
// TODO(knorton): Make sure this key is not already set.
object.put(keyBuffer.toString(), (JsonValue)nextValue());
switch (nextNonWhitespace()) {
case ',':
break;
case '}':
return object;
default:
throw new JsonException(
"Invalid object: expecting } or ,");
}
}else{
throw new JsonException("Invalid object: ");
}
}
}
}