I'm using the Android Asynchronous Http Client. My code looks like this and is working fine.
DataUtil.post("RegisterUser", params, new AsyncHttpResponseHandler() {
@Override
public void onSuccess(String answer) {
// initialize variables
JSONObject json = new JSONObject();
String message = null;
try {
// turn string into JSONObject
json = new JSONObject(answer);
message = json.getString("message");
} catch (JSONException e) {
Log.e("ERROR", e.getMessage());
}
// registration was successful
if (message.equals("success")) {
// forward to login page
} else {
// error
}
}
});
I implemented a static HTTP Client. My server returns this JSON data {"message":"success"}
. I do not want to treat it as a String and cast it back to JSON. But when I change it to public void onSuccess(JSONObject answer)
eclipse tells me
The method onSuccess(JSONObject) of type new AsyncHttpResponseHandler(){} must override or implement a supertype method
The correct method signature would be this public void onSuccess(int statusCode, Header[] headers, JSONObject response)
or any of the other available methods in the JsonHttpResponseHandler
class