问题
I have a gson.JsonObject object. What is the easiest way to create a org.json.JSONObject object from it?
回答1:
get JSON string again from JsonObject and parse it in JSONObject
JsonObject gson = new JsonParser().parse("{\"id\":\"value\"}").getAsJsonObject();
JSONObject jo2 = new JSONObject(gson.toString());
回答2:
new org.json.JSONObject(gson.toJson(gson.JsonObject));
来源:https://stackoverflow.com/questions/43976443/convert-a-gson-jsonobject-to-jsonobject