【问题标题】:Json conversion using Gson使用 Gson 进行 Json 转换
【发布时间】:2011-06-16 04:53:07
【问题描述】:

您好,我有以下课程,需要使用 Gson 转换传入的 Json

public class JsonConverter<T>{

private boolean success = Boolean.TRUE;
private List<T> data;
private int total;
private String message;

public JsonConverter(){

}

public JsonConverter(List<T> data, int count){
    this.data = data;
    this.total = count;
} //getters and setters

我有一个传入的 Json,其数据属性包含一些具有以下定义的类的值:

class A {private long calendarId;
private String title;
private String description;
private int colorId;
private boolean isHidden;
private long userId; //getter and setter

}

示例: json字符串:

{"data":{"calendarId":"ext-gen223","title":"work","description":"work","isHidden":false,"colorId":"2"}}

我想从 Json String 中获取值并将其设置在 List data 中(应该是 A 类对象列表 ) 的类 JsonConverter 使用 Gson。

谢谢

【问题讨论】:

    标签: json gson


    【解决方案1】:

    使用Type type = new TypeToken&lt;JsonConverter&lt;A&gt;&gt;(){}.getType(); 并让它运行起来!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-02
      • 2022-01-03
      • 1970-01-01
      相关资源
      最近更新 更多