我有以下代码
JsonArrayRequest req = new JsonArrayRequest(URL,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
if (status == 202) {
// try again} else {
// do something
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.w("Request", "That didn't work!");
}
});
queue.add(req);
但我不知道如何在我的代码中获得状态代码。
答案 0 :(得分:3)
您需要覆盖此方法
@Override
protected Response<JSONArray> parseNetworkResponse(NetworkResponse response) {
response.statusCode
}
问候。
答案 1 :(得分:2)
您可以参考以下代码:
JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(URL, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
// do something...
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// do something...
}
}) {
@Override
protected Response<JSONArray> parseNetworkResponse(NetworkResponse response) {
int statusCode = response.statusCode;
if (statusCode == 202) {
// do something...
} else {
// do something...
}
...
}
};
希望这有帮助!