Android 如何使用 Retrofit 传递嵌入式查询参数...这是我的 GET METHOD Url:
localhost:5000/at_invitations?embedded={"invitee":1}
我的问题是如何{"invitee":1}
使用 Retrofit将嵌入值作为查询参数传递。
这是我的服务调用声明代码:
@GET("at_invitations")
Call<JsonElement> invitationLists(
@Header("Authorization") String token,
@Query("embedded") String embedded
);
这是我的服务呼叫代码:
String token = App.getInstance().getToken();
AppearancesService service = App.getInstance().getRESTClient().create(AppearancesService.class);
Call<JsonElement> call = service.invitationLists(token, "{invitee:1}");
call.enqueue(new Callback<JsonElement>() {
@Override
public void onResponse(Call<JsonElement> call, Response<JsonElement> response) {
if (response.code() == 200) {
Log.v(TAG,"Success"+ response.body(););
}
}
}
@Override
public void onFailure(Call<JsonElement> call, Throwable t) {
System.out.println("Failed");
}
});
这是错误行:(如何声明这个值( "{"invitee":1}"
))
Call<JsonElement> call = service.invitationLists(token, "{"invitee":1}");
请帮帮我..谢谢..
试试这个
JSONObject jsonObject=new JSONObject();
try {
jsonObject.put("invite",1);
String a=jsonObject.toString();
} catch (JSONException e) {
e.printStackTrace();
}
这里的字符串“a”将具有您想要的格式,您的电话应该是这样的
@GET("at_invitations?")
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句