I use Retrofit to call the API. I am sending an API mail request, but in the callback I get empty JSON, like this {}.
Below is the RetrofitService code
@POST("/com/searchusers.php") void getUser(@Body JSONObject searchstring, Callback<JSONObject> callBack);
where searchstring JSON is like this {"search": "nitesh"}. In response, I should get the details of the user "nitesh".
Below is the code to send a POST request
RetrofitService mRetrofitService = app.getRetrofitService(); mRetrofitService.getUser(user, new Callback<JSONObject>() { @Override public void success(JSONObject result, Response arg1) { System.out.println("success, result: " + result); } @Override public void failure(RetrofitError error) { System.out.println("failure, error: " + error); } });
I get this conclusion success, result: {}
Expected Result: success, result: {"name": "nitesh", .... the rest of the details}
Edit: I tried using Response instead of JSONObject, like this CallBack<Response> , and then I converted the original response to String and got the expected result. But the problem is that in String I want to get the answer in JSONObject.
How to get the exact result using CallBack<JSONObject> ...?
json android post retrofit
Nitesh Khatri May 25 '14 at 8:49 a.m. 2014-05-25 08:49
source share