使用自定义凌空POST不返回任何东西 [英] Using custom Volley POST doesn't return anything

查看:132
本文介绍了使用自定义凌空POST不返回任何东西的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用扩展JsonRequest类的自定义类使用POST和参数发送JSONArrayRequest。

I'm trying to use a custom Class that extend the JsonRequest class to send a JSONArrayRequest using POST and a parameter.

public class MethodJsonArrayRequest extends JsonRequest<JSONArray> {
    public MethodJsonArrayRequest(int method, String url, JSONObject params, com.android.volley.Response.Listener<org.json.JSONArray> listener, ErrorListener errorListener) {
        super(method, url, params.toString(), listener, errorListener);
        Log.d("method", Integer.toString(method));
        Log.d("jsonRequest", params.toString());
    }

    @Override
    protected Response<JSONArray> parseNetworkResponse(NetworkResponse response) {
        try {
            String jsonString = new String(response.data,
                    HttpHeaderParser.parseCharset(response.headers));
            return Response.success(new JSONArray(jsonString),
                    HttpHeaderParser.parseCacheHeaders(response));
        } catch (UnsupportedEncodingException e) {
            return Response.error(new ParseError(e));
        } catch (JSONException je) {
            return Response.error(new ParseError(je));
        }
    }
}

我的日志返回此:

My logs return this:

D/method﹕ 1
D/jsonRequest﹕ {"idShow":"219"}

我传递这个信息到我的自定义类与此SNIPPIT:

I'm passing this info to my custom class with this snippit:

...
        JSONObject params = new JSONObject();
        try {
            params.put("idShow", idShow);
        }
        catch (JSONException e) {Log.d("JSON e", e.getMessage()); }

        MethodJsonArrayRequest episodeRequest = new MethodJsonArrayRequest(Request.Method.POST, episodeURL, params, new Response.Listener<JSONArray>() {
        @Override
        public void onResponse(JSONArray myResponse) {
            try {
                Log.d("myResponse", myResponse.toString());
...

myResponse的日志:

Log of myResponse:

D/myResponse﹕ []

但不管是什么原因,它不返回任何东西,我觉得我可能未通过正确的事了,但paramas我不知道,任何帮助是极大的AP preciated!让我知道如果有什么我没在这里包括那些可能会有所帮助。

But for whatever reason it does not return anything, I feel like I might not be passing the right thing in for the paramas but I'm not sure, any help is greatly appreciated! Let me know if there is something I didn't include here that might be helpful.

推荐答案

user98239820回答<一个href=\"http://stackoverflow.com/questions/18048806/volley-sending-a-post-request-using-jsonarrayrequest\">here是extreamly有用。相反,延长 JsonRequest&LT; JSONArray&GT; 类,他扩展了请求类。我也不得不改变他的新的JSONObject 新建JSONArray 适合我的需要,而是指向该类作品完美

user98239820 answer here was extreamly useful. Instead of extending JsonRequest<JSONArray> class he extended the Request class. I also had to change his new JSONObject to new JSONArray to fit my needs, but by pointing to that class works perfectly.

这篇关于使用自定义凌空POST不返回任何东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆