我要讓GET
請求,並使用不同的參數名稱來獲取對象數組:改造獲得與不同的對象
{
"monday": {
"open_time": "06:30",
"close_time": "20:30"
},
"tuesday": {
"open_time": "06:30",
"close_time": "20:30"
},
"wednesday": {
"open_time": "06:30",
"close_time": "20:30"
},
"thursday": {
"open_time": "06:30",
"close_time": "20:30"
},
"friday": {
"open_time": "06:30",
"close_time": "20:30"
},
"saturday": {
"open_time": "08:00",
"close_time": "19:00"
},
"sunday": {
"open_time": "08:00",
"close_time": "19:00"
}
}
所以我做了DayEntity,但不知道如何使用我的週一,週二ECT? 服務jsonschema2pojo希望從週一到週日創建大量的課程。
public class DayEntity {
@SerializedName("open_time")
@Expose
private String openTime;
@SerializedName("close_time")
@Expose
private String closeTime;
public void setOpenTime(String openTime) {
this.openTime = openTime;
}
public void setCloseTime(String closeTime) {
this.closeTime = closeTime;
}
UDP:如果GSON可以解析很好如何與改造相結合使用嗎?我有WeekEntity它空指針返回我的成功()
public class WeekEntity {
public HashMap<String, DayEntity> week;
public HashMap<String, DayEntity> getWeek() {
return week;
}
}
public void getBusinessHours(final Context context) {
RestAdapter restAdapter = formatHeader(NetworkConstants.BUSINESS_HOURS_URL);
restAdapter.create(ApiService.class).getBusinessHours(new Callback<WeekEntity>() {
@Override
public void success(WeekEntity weekEntity, Response response) {
Log.v("~~~~~success", weekEntity.getWeek().toString());
}
@Override
public void failure(RetrofitError error){
}
});
}
現在我有改造iteraction這樣,它作爲weekEntity所有的時間'@覆蓋 公共無效成功(WeekEntity weekEntity,響應響應)返回null {}' –
您確定,您的服務器返回上面列出的JSON? –