请指导如何使用gson库将String转换为JsonObject。
我的无效尝试:
我的无效尝试:
String string = "abcde";
Gson gson = new Gson();
JsonObject json = new JsonObject();
json = gson.toJson(string); // Can't convert String to JsonObject
JsonObject jo = jsonParser.parse(json).getAsJsonObject();
andAssert.assertTrue(jo.get("Success").getAsBoolean());
- smac89JsonParser
has been restructured since this answer. You should now use the one-linerJsonObject jsonObj = JsonParser.parseString(json).getAsJsonObject();
- squaregoldfish