【发布时间】:2014-06-23 04:29:38
【问题描述】:
我知道使用 JsonArrayRequest 的 POST 请求在 Volley 中不可用,但我看到这篇文章 here 谈到了添加一个构造函数来处理这个问题。他们的实现是这样的:
public JsonArrayRequest(int method, String url, JSONObject jsonRequest,
Listener<JSONArray> listener, ErrorListener errorListener) {
super(method, url, (jsonRequest == null) ? null : jsonRequest.toString(),
listener, errorListener);
}
我将如何将它添加为构造函数?上面的问题提到将它放在 Volley Tool Library 中。我将 Volley 作为 .jar 导入,所以我不确定如何添加这样的构造函数,或者这是否是最好的方法。非常感谢任何帮助。
编辑
我已经按照建议创建了以下具有覆盖和构造函数的类。这是课程:
public class PostJsonArrayRequest extends JsonArrayRequest {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
HashMap<String, String> params = new HashMap<String, String>();
params.put("name", "value");
return params;
}
public PostJsonArrayRequest(int method, String url, JSONObject jsonRequest,
Listener<JSONArray> listener, ErrorListener errorListener) {
super(Method.POST, url, null, listener, errorListener);
}
}
在拨打超级电话时,我收到了The constructor JsonArrayRequest(int, String, null, Response.Listener<JSONArray>, Response.ErrorListener) is undefined
我该如何纠正这个问题?
【问题讨论】:
-
子类 JsonArrayRequest,把构造函数放在那里