Retrofit Response
So i have this JSON Response from a server:
"result":
"id": 30,
"status": "Successful."
And a java class where:
public class JSONResponse
@SerializedName("result")
public JsonObject res;
@SerializedName("id")
public int id;
@SerializedName("status")
public String msg;
And here is where i call the service:
customerResponseCall.enqueue(new Callback<CustomerRequestResponse>()
@Override
public void onResponse(Call<CustomerRequestResponse> call, Response<CustomerRequestResponse> response)
response.body().res.get(String.valueOf(response.body().id));
Toast.makeText(MainActivity.this, "User Registed Successfully!!!" + "n" + "User ID = " + response.body().id, Toast.LENGTH_LONG).show();// this your result
@Override
public void onFailure(Call<CustomerRequestResponse> call, Throwable t)
Log.e("response-failure", call.toString());
);
And i want to be able to get the value of the id when there is a response from server. How do i go about this? Please Help
add a comment |
So i have this JSON Response from a server:
"result":
"id": 30,
"status": "Successful."
And a java class where:
public class JSONResponse
@SerializedName("result")
public JsonObject res;
@SerializedName("id")
public int id;
@SerializedName("status")
public String msg;
And here is where i call the service:
customerResponseCall.enqueue(new Callback<CustomerRequestResponse>()
@Override
public void onResponse(Call<CustomerRequestResponse> call, Response<CustomerRequestResponse> response)
response.body().res.get(String.valueOf(response.body().id));
Toast.makeText(MainActivity.this, "User Registed Successfully!!!" + "n" + "User ID = " + response.body().id, Toast.LENGTH_LONG).show();// this your result
@Override
public void onFailure(Call<CustomerRequestResponse> call, Throwable t)
Log.e("response-failure", call.toString());
);
And i want to be able to get the value of the id when there is a response from server. How do i go about this? Please Help
Can you post your Retrofit Client code please? also your CustomerRequestResponse class
– Ümañg ßürmån
Nov 15 '18 at 5:54
add a comment |
So i have this JSON Response from a server:
"result":
"id": 30,
"status": "Successful."
And a java class where:
public class JSONResponse
@SerializedName("result")
public JsonObject res;
@SerializedName("id")
public int id;
@SerializedName("status")
public String msg;
And here is where i call the service:
customerResponseCall.enqueue(new Callback<CustomerRequestResponse>()
@Override
public void onResponse(Call<CustomerRequestResponse> call, Response<CustomerRequestResponse> response)
response.body().res.get(String.valueOf(response.body().id));
Toast.makeText(MainActivity.this, "User Registed Successfully!!!" + "n" + "User ID = " + response.body().id, Toast.LENGTH_LONG).show();// this your result
@Override
public void onFailure(Call<CustomerRequestResponse> call, Throwable t)
Log.e("response-failure", call.toString());
);
And i want to be able to get the value of the id when there is a response from server. How do i go about this? Please Help
So i have this JSON Response from a server:
"result":
"id": 30,
"status": "Successful."
And a java class where:
public class JSONResponse
@SerializedName("result")
public JsonObject res;
@SerializedName("id")
public int id;
@SerializedName("status")
public String msg;
And here is where i call the service:
customerResponseCall.enqueue(new Callback<CustomerRequestResponse>()
@Override
public void onResponse(Call<CustomerRequestResponse> call, Response<CustomerRequestResponse> response)
response.body().res.get(String.valueOf(response.body().id));
Toast.makeText(MainActivity.this, "User Registed Successfully!!!" + "n" + "User ID = " + response.body().id, Toast.LENGTH_LONG).show();// this your result
@Override
public void onFailure(Call<CustomerRequestResponse> call, Throwable t)
Log.e("response-failure", call.toString());
);
And i want to be able to get the value of the id when there is a response from server. How do i go about this? Please Help
asked Nov 15 '18 at 5:39
S.JayS.Jay
73
73
Can you post your Retrofit Client code please? also your CustomerRequestResponse class
– Ümañg ßürmån
Nov 15 '18 at 5:54
add a comment |
Can you post your Retrofit Client code please? also your CustomerRequestResponse class
– Ümañg ßürmån
Nov 15 '18 at 5:54
Can you post your Retrofit Client code please? also your CustomerRequestResponse class
– Ümañg ßürmån
Nov 15 '18 at 5:54
Can you post your Retrofit Client code please? also your CustomerRequestResponse class
– Ümañg ßürmån
Nov 15 '18 at 5:54
add a comment |
1 Answer
1
active
oldest
votes
Change you JSONResponse as below; because JSON you're getting has JSONObject result
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class CustomerRequestResponse
@SerializedName("result")
@Expose
private Result result;
public Result getResult()
return result;
public void setResult(Result result)
this.result = result;
Result Class
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Result
@SerializedName("id")
@Expose
private Integer id;
@SerializedName("status")
@Expose
private String status;
public Integer getId()
return id;
public void setId(Integer id)
this.id = id;
public String getStatus()
return status;
public void setStatus(String status)
this.status = status;
Change your code as
customerResponseCall.enqueue(new Callback<CustomerRequestResponse>()
@Override
public void onResponse(Call<CustomerRequestResponse> call, Response<CustomerRequestResponse> response)
Integer id = response.body().getResult().getId();
Toast.makeText(MainActivity.this, "User Registered Successfully!!!" + "n" + "User ID = " + id, Toast.LENGTH_LONG).show();// this your result
@Override
public void onFailure(Call<CustomerRequestResponse> call, Throwable t)
Log.e("response-failure", call.toString());
);
1
because JSON you're getting has JSONArray result.resultisJSONObjectnotJSONArray.
– Piyush
Nov 15 '18 at 5:53
Thank you, but that's not what am looking for. I have gotten the result but i specifically wanted to get the value of the id. I tried your method but it, as tried to get the response.body() there is no way that i can get the id.
– S.Jay
Nov 15 '18 at 5:53
Thank you @Piyush :) My bad.. but Fixed now !
– Ali Ahmed
Nov 15 '18 at 5:55
@S.Jay have you added my code for fetching response ?
– Ali Ahmed
Nov 15 '18 at 5:56
1
@Ali Ahmed Thank you very much it worked for me.
– S.Jay
Nov 15 '18 at 6:10
add a comment |
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53313087%2fretrofit-response%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Change you JSONResponse as below; because JSON you're getting has JSONObject result
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class CustomerRequestResponse
@SerializedName("result")
@Expose
private Result result;
public Result getResult()
return result;
public void setResult(Result result)
this.result = result;
Result Class
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Result
@SerializedName("id")
@Expose
private Integer id;
@SerializedName("status")
@Expose
private String status;
public Integer getId()
return id;
public void setId(Integer id)
this.id = id;
public String getStatus()
return status;
public void setStatus(String status)
this.status = status;
Change your code as
customerResponseCall.enqueue(new Callback<CustomerRequestResponse>()
@Override
public void onResponse(Call<CustomerRequestResponse> call, Response<CustomerRequestResponse> response)
Integer id = response.body().getResult().getId();
Toast.makeText(MainActivity.this, "User Registered Successfully!!!" + "n" + "User ID = " + id, Toast.LENGTH_LONG).show();// this your result
@Override
public void onFailure(Call<CustomerRequestResponse> call, Throwable t)
Log.e("response-failure", call.toString());
);
1
because JSON you're getting has JSONArray result.resultisJSONObjectnotJSONArray.
– Piyush
Nov 15 '18 at 5:53
Thank you, but that's not what am looking for. I have gotten the result but i specifically wanted to get the value of the id. I tried your method but it, as tried to get the response.body() there is no way that i can get the id.
– S.Jay
Nov 15 '18 at 5:53
Thank you @Piyush :) My bad.. but Fixed now !
– Ali Ahmed
Nov 15 '18 at 5:55
@S.Jay have you added my code for fetching response ?
– Ali Ahmed
Nov 15 '18 at 5:56
1
@Ali Ahmed Thank you very much it worked for me.
– S.Jay
Nov 15 '18 at 6:10
add a comment |
Change you JSONResponse as below; because JSON you're getting has JSONObject result
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class CustomerRequestResponse
@SerializedName("result")
@Expose
private Result result;
public Result getResult()
return result;
public void setResult(Result result)
this.result = result;
Result Class
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Result
@SerializedName("id")
@Expose
private Integer id;
@SerializedName("status")
@Expose
private String status;
public Integer getId()
return id;
public void setId(Integer id)
this.id = id;
public String getStatus()
return status;
public void setStatus(String status)
this.status = status;
Change your code as
customerResponseCall.enqueue(new Callback<CustomerRequestResponse>()
@Override
public void onResponse(Call<CustomerRequestResponse> call, Response<CustomerRequestResponse> response)
Integer id = response.body().getResult().getId();
Toast.makeText(MainActivity.this, "User Registered Successfully!!!" + "n" + "User ID = " + id, Toast.LENGTH_LONG).show();// this your result
@Override
public void onFailure(Call<CustomerRequestResponse> call, Throwable t)
Log.e("response-failure", call.toString());
);
1
because JSON you're getting has JSONArray result.resultisJSONObjectnotJSONArray.
– Piyush
Nov 15 '18 at 5:53
Thank you, but that's not what am looking for. I have gotten the result but i specifically wanted to get the value of the id. I tried your method but it, as tried to get the response.body() there is no way that i can get the id.
– S.Jay
Nov 15 '18 at 5:53
Thank you @Piyush :) My bad.. but Fixed now !
– Ali Ahmed
Nov 15 '18 at 5:55
@S.Jay have you added my code for fetching response ?
– Ali Ahmed
Nov 15 '18 at 5:56
1
@Ali Ahmed Thank you very much it worked for me.
– S.Jay
Nov 15 '18 at 6:10
add a comment |
Change you JSONResponse as below; because JSON you're getting has JSONObject result
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class CustomerRequestResponse
@SerializedName("result")
@Expose
private Result result;
public Result getResult()
return result;
public void setResult(Result result)
this.result = result;
Result Class
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Result
@SerializedName("id")
@Expose
private Integer id;
@SerializedName("status")
@Expose
private String status;
public Integer getId()
return id;
public void setId(Integer id)
this.id = id;
public String getStatus()
return status;
public void setStatus(String status)
this.status = status;
Change your code as
customerResponseCall.enqueue(new Callback<CustomerRequestResponse>()
@Override
public void onResponse(Call<CustomerRequestResponse> call, Response<CustomerRequestResponse> response)
Integer id = response.body().getResult().getId();
Toast.makeText(MainActivity.this, "User Registered Successfully!!!" + "n" + "User ID = " + id, Toast.LENGTH_LONG).show();// this your result
@Override
public void onFailure(Call<CustomerRequestResponse> call, Throwable t)
Log.e("response-failure", call.toString());
);
Change you JSONResponse as below; because JSON you're getting has JSONObject result
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class CustomerRequestResponse
@SerializedName("result")
@Expose
private Result result;
public Result getResult()
return result;
public void setResult(Result result)
this.result = result;
Result Class
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Result
@SerializedName("id")
@Expose
private Integer id;
@SerializedName("status")
@Expose
private String status;
public Integer getId()
return id;
public void setId(Integer id)
this.id = id;
public String getStatus()
return status;
public void setStatus(String status)
this.status = status;
Change your code as
customerResponseCall.enqueue(new Callback<CustomerRequestResponse>()
@Override
public void onResponse(Call<CustomerRequestResponse> call, Response<CustomerRequestResponse> response)
Integer id = response.body().getResult().getId();
Toast.makeText(MainActivity.this, "User Registered Successfully!!!" + "n" + "User ID = " + id, Toast.LENGTH_LONG).show();// this your result
@Override
public void onFailure(Call<CustomerRequestResponse> call, Throwable t)
Log.e("response-failure", call.toString());
);
edited Nov 15 '18 at 5:55
answered Nov 15 '18 at 5:41
Ali AhmedAli Ahmed
1,3891314
1,3891314
1
because JSON you're getting has JSONArray result.resultisJSONObjectnotJSONArray.
– Piyush
Nov 15 '18 at 5:53
Thank you, but that's not what am looking for. I have gotten the result but i specifically wanted to get the value of the id. I tried your method but it, as tried to get the response.body() there is no way that i can get the id.
– S.Jay
Nov 15 '18 at 5:53
Thank you @Piyush :) My bad.. but Fixed now !
– Ali Ahmed
Nov 15 '18 at 5:55
@S.Jay have you added my code for fetching response ?
– Ali Ahmed
Nov 15 '18 at 5:56
1
@Ali Ahmed Thank you very much it worked for me.
– S.Jay
Nov 15 '18 at 6:10
add a comment |
1
because JSON you're getting has JSONArray result.resultisJSONObjectnotJSONArray.
– Piyush
Nov 15 '18 at 5:53
Thank you, but that's not what am looking for. I have gotten the result but i specifically wanted to get the value of the id. I tried your method but it, as tried to get the response.body() there is no way that i can get the id.
– S.Jay
Nov 15 '18 at 5:53
Thank you @Piyush :) My bad.. but Fixed now !
– Ali Ahmed
Nov 15 '18 at 5:55
@S.Jay have you added my code for fetching response ?
– Ali Ahmed
Nov 15 '18 at 5:56
1
@Ali Ahmed Thank you very much it worked for me.
– S.Jay
Nov 15 '18 at 6:10
1
1
because JSON you're getting has JSONArray result.
result is JSONObject not JSONArray.– Piyush
Nov 15 '18 at 5:53
because JSON you're getting has JSONArray result.
result is JSONObject not JSONArray.– Piyush
Nov 15 '18 at 5:53
Thank you, but that's not what am looking for. I have gotten the result but i specifically wanted to get the value of the id. I tried your method but it, as tried to get the response.body() there is no way that i can get the id.
– S.Jay
Nov 15 '18 at 5:53
Thank you, but that's not what am looking for. I have gotten the result but i specifically wanted to get the value of the id. I tried your method but it, as tried to get the response.body() there is no way that i can get the id.
– S.Jay
Nov 15 '18 at 5:53
Thank you @Piyush :) My bad.. but Fixed now !
– Ali Ahmed
Nov 15 '18 at 5:55
Thank you @Piyush :) My bad.. but Fixed now !
– Ali Ahmed
Nov 15 '18 at 5:55
@S.Jay have you added my code for fetching response ?
– Ali Ahmed
Nov 15 '18 at 5:56
@S.Jay have you added my code for fetching response ?
– Ali Ahmed
Nov 15 '18 at 5:56
1
1
@Ali Ahmed Thank you very much it worked for me.
– S.Jay
Nov 15 '18 at 6:10
@Ali Ahmed Thank you very much it worked for me.
– S.Jay
Nov 15 '18 at 6:10
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53313087%2fretrofit-response%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown

Can you post your Retrofit Client code please? also your CustomerRequestResponse class
– Ümañg ßürmån
Nov 15 '18 at 5:54