1 ##导入依赖的jar
compile 'com.google.code.gson:gson:2.8.1'
2 ##创建Bean对象
package www.imooc.com.main;
import java.util.List;
/**
* Date: 2017/7/25 15:00
* Author: 00
* Description: TODO
*/
public class DetailList {
private List<DetailBean> detail;
public List<DetailBean> getDetail() {
return detail;
}
public void setDetail(List<DetailBean> detail) {
this.detail = detail;
}
public static class DetailBean {
private int id;
private String name;
private String address;
private String serviceNames;
private long createTime;
private long serviceTime;
private String contactPhone;
private String state;
private int stateNumber;
private Object type;
private int commentState;
private long responseTime;
private int confirmState;
private String total;
private int comefrom;
private int callingId;
private String description;
private int employeeId;
private Object employeeName;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getServiceNames() {
return serviceNames;
}
public void setServiceNames(String serviceNames) {
this.serviceNames = serviceNames;
}
public long getCreateTime() {
return createTime;
}
public void setCreateTime(long createTime) {
this.createTime = createTime;
}
public long getServiceTime() {
return serviceTime;
}
public void setServiceTime(long serviceTime) {
this.serviceTime = serviceTime;
}
public String getContactPhone() {
return contactPhone;
}
public void setContactPhone(String contactPhone) {
this.contactPhone = contactPhone;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public int getStateNumber() {
return stateNumber;
}
public void setStateNumber(int stateNumber) {
this.stateNumber = stateNumber;
}
public Object getType() {
return type;
}
public void setType(Object type) {
this.type = type;
}
public int getCommentState() {
return commentState;
}
public void setCommentState(int commentState) {
this.commentState = commentState;
}
public long getResponseTime() {
return responseTime;
}
public void setResponseTime(long responseTime) {
this.responseTime = responseTime;
}
public int getConfirmState() {
return confirmState;
}
public void setConfirmState(int confirmState) {
this.confirmState = confirmState;
}
public String getTotal() {
return total;
}
public void setTotal(String total) {
this.total = total;
}
public int getComefrom() {
return comefrom;
}
public void setComefrom(int comefrom) {
this.comefrom = comefrom;
}
public int getCallingId() {
return callingId;
}
public void setCallingId(int callingId) {
this.callingId = callingId;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public int getEmployeeId() {
return employeeId;
}
public void setEmployeeId(int employeeId) {
this.employeeId = employeeId;
}
public Object getEmployeeName() {
return employeeName;
}
public void setEmployeeName(Object employeeName) {
this.employeeName = employeeName;
}
}
}
3 ##解析json
Gson gson = new Gson();
DetailList detailBean = gson.fromJson(str, DetailList.class);
就是这么简单~ str 是下载好的json字符串。