【问题标题】:Android JSON parsing using the Gson Library [closed]使用 Gson 库解析 Android JSON [关闭]
【发布时间】:2016-12-02 05:11:55
【问题描述】:

我想使用 Gson 库解析以下数据。

{
    "claimTypeList": [
        "Dental",
        "Outpatient",
        "Hospitalisation/Surgery"
    ]
}

【问题讨论】:

    标签: java json gson


    【解决方案1】:
    @Generated("org.jsonschema2pojo")
    public class Example {
    
    @SerializedName("claimTypeList")
    @Expose
    private List<String> claimTypeList = new ArrayList<String>();
    
    /**
    *
    * @return
    * The claimTypeList
    */
    public List<String> getClaimTypeList() {
    return claimTypeList;
    }
    
    /**
    *
    * @param claimTypeList
    * The claimTypeList
    */
    public void setClaimTypeList(List<String> claimTypeList) {
    this.claimTypeList = claimTypeList;
    }
    
    }
    

    http://www.jsonschema2pojo.org/

    【讨论】:

      【解决方案2】:

      像这样创建一个模型类

      public class Claims {
          List<String> claimTypes; 
      }
      

      在这里将您的字符串转换为对象

      String data = "{\"claimTypeList\":[\"Dental\",\"Outpatient\",\"Hospitalisation/Surgery\"]}"
      Claims c = new Claims();
      c = new Gson().FromJson(data, Claims.class);
      

      希望这会有所帮助。

      【讨论】:

        猜你喜欢
        • 2018-07-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多