JSONObject (org.json) to JsonElement(com.google.gson)

匿名 (未验证) 提交于 2019-12-03 01:38:01

问题:

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); 


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