I am writing a java code in which i need to convert a JSONObject to JsonElement.Is there any way using which i can convert a JSONObject (org.json) to JsonElement(com.google.gson)?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
One way that always works is to serialize the object to JSON and then parse it again:
JSONObject myData = ... Gson gson = new Gson(); JsonElement element = gson.fromJson(myData.toString(), JsonElement.class);