I have a problem about getting value from php file and showing it as a Toast message.
I get result value as “null”.
How can I fix it?
Here is my php code.
...
$x = (array('Result' => "Successful"));
echo json_encode($x,JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT);
...
android code
x.enqueue(new Callback<Result>() {
@Override
public void onResponse(Call<Result> call, Response<Result> response) {
if(response.isSuccessful()){
Result result = response.body();
String message = result.getResult();
Log.i(LOG,"gonder() | onResponse : " + message);
Toast.makeText(getApplicationContext(),
message, Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(Call<Result> call, Throwable t) {
}
});
2
Answers
My answer,
I changed the variable as "result" instead of defing "Result" and I fix the issue.
In php use the json_encode
And In android before showing the response message as as a Toast message you can check you are getting the Successful message or not.
Like.