JsonParser { public static JsonObject parseJsonObject(String json) { JsonLexer lexer = new JsonLexer(json); JsonToken t = lexer.poll(); if (null == t || JsonTokenKind.BEGIN_OBJECT != t.getKind()) { Log.error("0xA0589 Json objects must begin with a '{'!"); return null; } return parseJsonObject(lexer); }  static JsonElement parse(String s); static JsonObject parseJsonObject(String json); static JsonArray parseJsonArray(String json); static JsonElement parseJson(JsonLexer lexer); static void enableObjectMemberTracing(); static void disableObjectMemberTracing();  }
@Test public void testSimpleObject() { JsonObject result = JsonParser.parseJsonObject("{\"foo\":false,\"bar\":3,\"bla\":\"yes\",\"blub\":3.4}"); assertTrue(result.getMember("foo").isJsonBoolean()); assertEquals(false, result.getMember("foo").getAsJsonBoolean().getValue()); assertTrue(result.getMember("bar").isJsonNumber()); assertEquals(3, result.getMember("bar").getAsJsonNumber().getNumberAsInt()); assertTrue(result.getMember("bla").isJsonString()); assertEquals("yes", result.getMember("bla").getAsJsonString().getValue()); assertTrue(result.getMember("blub").isJsonNumber()); assertEquals(3.4, result.getMember("blub").getAsJsonNumber().getNumberAsDouble(), 0.1); assertTrue( JsonParser.parseJsonObject("{}").isJsonObject()); }