Android How to pass embedded query parameters using Retrofit... This is my GET METHOD Url:
localhost:5000/at_invitations?embedded={"invitee":1}
My Question is how to pass the embedded value {"invitee":1}
as query parameter using Retrofit..
This is My Service Call declaration Code :
@GET("at_invitations")
Call<JsonElement> invitationLists(
@Header("Authorization") String token,
@Query("embedded") String embedded
);
This My Service Call Code :
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");
}
});
This is error Line :(How to declare this value( "{"invitee":1}"
))
Call<JsonElement> call = service.invitationLists(token, "{"invitee":1}");
Please help me.. Thanks..
try this out
JSONObject jsonObject=new JSONObject();
try {
jsonObject.put("invite",1);
String a=jsonObject.toString();
} catch (JSONException e) {
e.printStackTrace();
}
here string "a" will have the format you want and your call should be like this
@GET("at_invitations?")
Hello Try this if it helps
your Service Interface
@Headers("Content-Type: application/json")
@POST("index.php")
Call<Model>getUserDetails(@QueryMap Map<String,JSONObject> stringTaskMap);
Method to get details
public void getDetails(Map<String, JSONObject> task) {
ServiceInterfaceApi interfaceApi = ServiceClass.getApiService();
Call<Model> call = interfaceApi.getUserDetails(task);
Log.v("@@@WWE", "Retrofit Request Method = " + call.request().method());
Log.v("@@@WWE", "Retrofit Request Body = " + call.request().body());
Log.v("@@@WWE", "Retrofit Request Url = " + call.request().url());
Log.v("@@@WWE", "Retrofit Request executed = " + call.isExecuted());
Log.v("@@@WWE", "Retrofit Request Headers= " + call.request().headers());
call.enqueue(new Callback<Model>() {
@Override
public void onResponse(Call<Model> call, Response<Model> response) {
Log.v("@@@", "Response");
if (response.isSuccessful()) {
Log.v("@@@", "Sucess");
}
}
@Override
public void onFailure(Call<Model> call, Throwable t) {
Log.v("@@@WWE", "Failure " + t.getMessage());
}
});
}
Calling the method where required
JSONObject taskM = new JSONObject();
try {
taskM.put("invitee", "1");
} catch (JSONException e) {
e.printStackTrace();
}
Map<String, JSONObject> taskMap = new HashMap<>();
taskMap.put("embedded", taskM);
getDetails(taskMap);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.