我有一个没有任何对象(键)的
JSON数组,其中有
JSON对象,如下所示:
[{"Type":"Meeting","Name":"TestMeeting","StartDate":"2016-03-22T08:00:00","EndDate":"2016-03-24T09:00:00"}]
我试图解析它但找不到成功,有人能建议我如何使用Retrofit解析这种类型的响应吗?
解决方法
您可以定义表示JSON对象的类
import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; public class Meeting{ @SerializedName("Type") @Expose private String type; @SerializedName("Name") @Expose private String name; @SerializedName("StartDate") @Expose private String startDate; @SerializedName("EndDate") @Expose private String endDate; public String getType() { return type; } public void setType(String type) { this.type = type; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getStartDate() { return startDate; } public void setStartDate(String startDate) { this.startDate = startDate; } public String getEndDate() { return endDate; } public void setEndDate(String endDate) { this.endDate = endDate; } }
之后,您可以像这样定义Callback进行改造调用<列表与LT;会议>> getMeetings();
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。