[英]How can I convert a JSONObject to a gson.JsonObject?
我有一個org.json.JSONObject
對象。
從中創建gson.JsonObject
對象的最簡單方法是什么?
謝謝
最簡單的方法是使用toString()將JSONObject序列化為json字符串,然后將該json字符串解析為JsonObject:
org.json.JSONObject object = <your defined object>;
JsonParser jsonParser = new JsonParser();
JsonObject gsonObject = (JsonObject)jsonParser.parse(object.toString());
請注意,序列化和反序列化對象可能是一項昂貴的操作。 如果你必須在你的代碼(內部循環)中做很多事情,它會影響你的性能。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.