Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert a gson.JsonObject to JSONObject

Tags:

java

gson

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

like image 621
nik Avatar asked May 15 '17 09:05

nik


Video Answer


2 Answers

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());
like image 100
Raman Sahasi Avatar answered Oct 14 '22 18:10

Raman Sahasi


new org.json.JSONObject(gson.toJson(gson.JsonObject));
like image 33
Mike Adamenko Avatar answered Oct 14 '22 18:10

Mike Adamenko