Convert gson.JsonObject to JSONObject

I have an object gson.JsonObject. What is the easiest way to create an object from it org.json.JSONObject?

Thanks in advance.

+6
source share
2 answers

get the JSON string again JsonObjectand parse it intoJsonObject

JsonObject gson = new JsonParser().parse("{\"id\":\"value\"}").getAsJsonObject();

JSONObject jo2 = new JSONObject(gson.toString());
+5
source
new org.json.JSONObject(gson.toJson(gson.JsonObject));
+3
source

Source: https://habr.com/ru/post/1017263/


All Articles