use JsonParser; for example:
JsonParser parser = new JsonParser();JsonObject o = parser.parse("{\"a\": \"A\"}").getAsJsonObject();
Try to use getAsJsonObject() instead of a straight cast used in the accepted answer:
getAsJsonObject()
JsonObject o = new JsonParser().parse("{\"a\": \"A\"}").getAsJsonObject();
String jsonStr = "{\"a\": \"A\"}";Gson gson = new Gson();JsonElement element = gson.fromJson (jsonStr, JsonElement.class);JsonObject jsonObj = element.getAsJsonObject();