通过改造将服务器列表发送到服务器:2.1.0 - Android?

时间:2017-02-12 11:52:51

标签: android retrofit retrofit2

我有ClassSchedule

public class ClassSchedule {
    private String Day;
    private String Time;

    public String getDay() {
        return Day;
    }

    public void setDay(String day) {
        Day = day;
    }

    public String getTime() {
        return Time;
    }

    public void setTime(String time) {
        Time = time;
    }
}

我设置的数据如下:

List<ClassSchedule> listSchedule = new ArrayList<>();
ClassSchedule classSchedule = new ClassSchedule();
classSchedule.setDay(weekDay);
classSchedule.setTime(startTime);
listSchedule.add(classSchedule);

如何使用listScheduleretrofit:2.1.0发送到服务器?

其他参数:

    Classes classesme = new Classes();
    classesme.setName(name);
    classesme.setCost(cost);
    classesme.setType(String.valueOf(spCost));
    classesme.setClass_Type(spClass);
    classesme.setProvince(nameState);
    classesme.setCity(city);
    classesme.setField_Name(field);
    classesme.setSection(section);
    classesme.setTerm(term);
    classesme.setYear(year);
    classesme.setAccess_Type(access);
    classesme.setUniversity_Name(nameUn);
    classesme.setDescription(desc);
    classesme.setDayStart(startDate);
    classesme.setDayEnd(endDate);

并且: String username =“Jim”;

在我的interface中:

public interface Interface_CreateClass {
    @POST("SetData/CreateClass")
    Call<JsonGet_CreateClass> getJSONCreateClass(@Query("username") String username,
                                                 @Body Classes classes,
                                                 @Body ClassSchedule classSchedule);
}

1 个答案:

答案 0 :(得分:0)

您只需将列表本身作为正文

发送
public interface Interface_CreateClass {
    @POST("SetData/CreateClass")
    Call<JsonGet_CreateClass> getJSONCreateClass(@Query("username") String username,
                                                 @Body List<ClassSchedule> classSchedule);
}

注意:我认为您在同一请求中不能将两个参数注释为Body