这是我在控制台中得到的:
onSuccess(int, Header[], JSONObject) was not overriden, but callback was received我验证过了,文件被上传到服务器上。
这是我的代码,应用程序不会抱怨:
public void uploadImage() {
//Create a new RequestParams that will send paremeters with our AsyncHttpClient request.
RequestParams data = new RequestParams();
//Adding our image to the parameters.
File image = new File(imgPath);
try {
data.put("image", image);
} catch(FileNotFoundException e) {}
//Create a new AsyncHttpClient request.
//here we're sending a POST request, the first parameter is the request URL
// then our RequestParams, in our case data and then a Json response handler.
AsyncHttpClient client = new AsyncHttpClient();
client.post(FILE_UPLOAD_URL, data, new JsonHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header headers[], JSONArray success) {
try {
JSONObject data = success.getJSONObject(0);
String m = data.getString("message");
Toast.makeText(UploadPhotoTest.this, m, Toast.LENGTH_LONG).show();
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}这是我导入的内容,如果它是相关的:
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import org.apache.http.Header;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;我的问题是OnSuccess中的任何东西都不会被执行。我在OnSuccess try和catch中放置了一个日志,但什么也没有打印出来。我该如何解决这个问题呢?
发布于 2016-03-04 06:29:25
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
这对我很有效。
发布于 2022-02-19 12:46:33
在所有地方使用JSONObject,在JSONArray中都会得到"Success“响应。
https://stackoverflow.com/questions/30616354
复制相似问题