【问题标题】:JSONObject (org.json) to JsonElement(com.google.gson)JSONObject (org.json) 到 JsonElement(com.google.gson)
【发布时间】:2016-11-17 12:32:40
【问题描述】:

我正在编写一个 java 代码,我需要在其中将 JSONObject 转换为 JsonElement。有什么方法可以将 JSONObject (org.json) 转换为 JsonElement(com.google.gson)?

【问题讨论】:

    标签: java json


    【解决方案1】:

    一种始终有效的方法是将对象序列化为 JSON,然后再次解析:

    JSONObject myData = ...
    Gson gson = new Gson();
    JsonElement element = gson.fromJson(myData.toString(), JsonElement.class);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-16
      • 2021-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多