Convert a gson.JsonObject to JSONObject

对着背影说爱祢 提交于 2019-12-19 05:07:04

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!