I have a gson.JsonObject
object. What is the easiest way to create a org.json.JSONObject
object from it?
Convert a gson.JsonObject to JSONObject
TBH having two different JSON Parsers in a single project sounds like an hassle and you should check if you can't provide all components of your project with a single parser library, rather than switching back and forth between the two APIs. –
Toneytong
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());
new org.json.JSONObject(gson.toJson(gson.JsonObject));
Consider json below as a JSONObject.
JsonObject gson = JsonParser.parseString( json.toString() ),getAsJsonObject();
© 2022 - 2024 — McMap. All rights reserved.