我的JSON参数:
{
"params":{
"model":"res.users",
"method": "read",
"args": [[907], ["name", "login", "image_small"]],
"kwargs": {},
"context": {
"from_searchview": true
}
}
我创建了一个要发布的参数类:
public class XPSCredsParamImage {
public XPSCredsParamImageDetail params;
public XPSCredsParamImage(String model, String method, String[][] args, String kwargs, Context context) {
this.params = new XPSCredsParamImageDetail(model, method, args, kwargs, context);
}
public static class XPSCredsParamImageDetail {
public String model;
public String method;
public String args[][];
public String kwargs;
public Context context;
public XPSCredsParamImageDetail(String model, String method, String[][] args, String kwargs, Context context) {
this.model = model;
this.method = method;
this.args = args;
this.kwargs = kwargs;
this.context = context;
}
}
public class Context {
public Boolean searchview;
public Context(Boolean searchview) {
this.searchview = searchview;
}
}
这是我的界面
public interface XPSApiEndpoint {
@POST("/web/dataset/call_kw")
Call<String> getImage(@Body XPSCredsParamImage param);
现在,我使用异步任务发布参数并将数据获取到JSONObject:
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... voids) {
XPSApiEndpoint xps = XPSClient.getXPSClient();
Call<String> call = xps.getImage(new XPSCredsParamImage());
String response = null;
但是我不知道如何将参数写入xps.getImage(new XPSCredsParamImage()); 我的参数很复杂。 我该怎么办?
答案 0 :(得分:0)
您的json数据(如果无效),您最后忘了'}'。
要为json创建合适的数据模型,您可以使用http://www.jsonschema2pojo.org/-它可以帮助您通过json创建模型。
然后,您应该用数据填充模型,并通过@Body标签进行翻新发送。