我有以下JSON:我應該如何定義我的模型類與Gson的安排?
{
_id: "5252fdf424f1e7fbf7000004",
address: "Calle 1000",
city: "Concepción",
created_at: "2013-10-07T18:31:19.375Z",
description: "",
name: "Joctos",
phone: "94967994",
updated_at: "2013-12-09T13:03:07.328Z",
happy_hour: {
active: false,
type: 1,
all_day: false,
start: "2013-12-17T03:30:00.000Z",
end: "2013-12-17T05:00:00.000Z"
}
}
告訴他們接收和JSON GSON我努力相信的對象時,probleam是,定義的對象如下
public class StoreModel {
@SerializedName("_id")
private String _id;
@SerializedName("address")
private String address;
@SerializedName("city")
private String city;
@SerializedName("created_at")
private String created_at;
@SerializedName("description")
private String description;
@SerializedName("name")
private String name;
@SerializedName("phone")
private String phone;
@SerializedName("updated_at")
private String updated_at;
public String get_id() {
return this._id;
}
public void set_id(String _id) {
this._id = _id;
}
public String getAddress() {
return this.address;
}
public void setAddress(String address) {
this.address = address;
}
public String getCity() {
return this.city;
}
public void setCity(String city) {
this.city = city;
}
public String getCreated_at() {
return this.created_at;
}
public void setCreated_at(String created_at) {
this.created_at = created_at;
}
public String getDescription() {
return this.description;
}
public void setDescription(String description) {
this.description = description;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public String getPhone() {
return this.phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getUpdated_at() {
return this.updated_at;
}
public void setUpdated_at(String updated_at) {
this.updated_at = updated_at;
}
}
我應該如何定義我的模型才能獲得「happy_hours」數據?
可以使消氣setter方法「happy_hour」以類似的方式爲你做其他的鍵。 –