我正在使用 Android Asynchronous Http Client .我的代码看起来像这样并且工作正常。
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
}
}
});
我实现了一个 static HTTP Client .我的服务器返回此 JSON 数据 {"message":"success"}
。我不想将其视为字符串并将其转换回 JSON。但是当我将它更改为 public void onSuccess(JSONObject answer)
eclipse 告诉我
The method onSuccess(JSONObject) of type new AsyncHttpResponseHandler(){} must override or implement a supertype method
最佳答案
正确的方法签名应该是这个 public void onSuccess(int statusCode, Header[] headers, JSONObject response)
或 JsonHttpResponseHandler
中的任何其他可用方法类
关于android - onSuccess - 异步 Http 客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23144295/