我如何在翻新中发布具有类名的数据

时间:2019-02-27 09:35:31

标签: android json gson retrofit2

我使用改造后的Web服务发布数据,但由于我这样发布而返回null;

{"username":"asd","password":"123"}

但是我想这样发布;

{user:{"username":"asd","password":"123"}}

这些是我的实体和调用方法;​​

public class User {

@SerializedName("username")
@Expose
public String username;

@SerializedName("password")
@Expose
public String password;
}

我的呼叫服务界面是这样的;

  @POST("/test/Logon")
Call<Result> getLogon(@Body User user);

我不想使用额外的类在其上传递用户。

1 个答案:

答案 0 :(得分:0)

尝试

  @POST("/test/Logon")
Call<Result> getLogon(@Body Map<String,Object> user);

将白色传递对象传递给getLogon

Map<String,Object> map = new HashMap();
map.put("user",userObject);
getLogon(map)
相关问题