将gson.JsonObject转换为JSONObject

时间:2017-05-15 09:54:47

标签: java gson

我有一个gson.JsonObject个对象。从中创建org.json.JSONObject对象的最简单方法是什么?

2 个答案:

答案 0 :(得分:18)

JsonObject再次获取JSON字符串,并在JSONObject

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

JSONObject jo2 = new JSONObject(gson.toString());

答案 1 :(得分:7)

new org.json.JSONObject(gson.toJson(gson.JsonObject));