将列表发送到改型后的服务器:2.1.0-Android?
我有一个将列表发送到改型后的服务器:2.1.0-Android?,android,retrofit,retrofit2,Android,Retrofit,Retrofit2,我有一个课程表: public class ClassSchedule { private String Day; private String Time; public String getDay() { return Day; } public void setDay(String day) { Day = day; } public String getTime() { retur
课程表
:
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);
以及:
字符串username=“Jim”
在我的界面中
是:
public interface Interface_CreateClass {
@POST("SetData/CreateClass")
Call<JsonGet_CreateClass> getJSONCreateClass(@Query("username") String username,
@Body Classes classes,
@Body ClassSchedule classSchedule);
}
公共接口\u CreateClass{
@POST(“设置数据/创建类”)
调用getJSONCreateClass(@Query(“username”)字符串username,
@身体课,
@身体分类表);
}
您只需将列表本身作为一个整体发送即可
public interface Interface_CreateClass {
@POST("SetData/CreateClass")
Call<JsonGet_CreateClass> getJSONCreateClass(@Query("username") String username,
@Body List<ClassSchedule> classSchedule);
}
公共接口\u CreateClass{
@POST(“设置数据/创建类”)
调用getJSONCreateClass(@Query(“username”)字符串username,
@机构名单(附表);
}
注意:我认为不能在同一个请求中将两个参数注释为
Body
。您可以将其转换为json,然后将其传输到服务器。到目前为止,您做了哪些尝试?您可以通过将@body List listSchedule
作为参数传递到接口,将其作为json发送到正文中。我尝试了@body ClassSchedule ClassSchedule,但第三个参数类型说错了。找到:'java.util.List',必需:'..ClassSchedule'我编辑了我的问题。给我多个“@Body方法注释已找到。(参数#3)”但我需要“@Body Classes”来发送其他数据!你不能派两个人去。那没有道理!您可以将这两个类包装在另一个类中,并将其作为Body
public interface Interface_CreateClass {
@POST("SetData/CreateClass")
Call<JsonGet_CreateClass> getJSONCreateClass(@Query("username") String username,
@Body List<ClassSchedule> classSchedule);
}