Андроид залп. JsonArray JsonException конец ввода на символе 0

Я пытаюсь получить jsonarray из URL-адреса, используя Volley. проблема в том, что я получаю

JsonException end of input at character 0

код следующий:

JsonArrayRequest req = new JsonArrayRequest(Request.Method.POST, openMatchesUrl,
                 new Response.Listener<JSONArray>() {
                    @Override
                    public void onResponse(JSONArray response) {
                        Log.d("JSON", response.toString());
                        try {
                            for (int i = 0; i < response.length(); i++) {

                                //do stuff
                            }

                        } catch (JSONException e) {
                            e.printStackTrace();
                            Toast.makeText(getApplicationContext(),
                                    "Error: " + e.getMessage(),
                                    Toast.LENGTH_LONG).show();
                        }

                    }
                }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Toast.makeText(getApplicationContext(),
                                "onErrorResponse ongoing: "+error.getMessage(), Toast.LENGTH_SHORT).show();
                    }
                }){     
        @Override
        protected Map<String, String> getParams() 
        {  
               //build params 
        }
    };
    // Add the request to the RequestQueue.
    queue.add(req);

Я думал, что проблема была в неправильных параметрах. но я попытался с помощью простого строкового запроса:

StringRequest req = new StringRequest(Request.Method.POST, openMatchesUrl,
                new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
                 Log.d("JSON", "resp: " +response);
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.d("JSON", error.toString());
        }
    }){     
            @Override
            protected Map<String, String> getParams() 
            {  
                    //build params 
            }
        };

и на самом деле он возвращает json правильно. Например:

[{"roundid":4152,"numberofplayers":1,"dateevent":"2015-04-13 19:45:32.121124+02","playernames":"cat","turn":1,"codedboard":""},{"roundid":415‌​4,"numberofplayers":1,"dateevent":"2015-04-13 20:16:08.845409+02","playernames":"cat","turn":1,"codedboard":""},{"roundid":415‌​5,"numberofplayers":1,"dateevent":"2015-04-13 20:18:22.002411+02","playernames":"cat","turn":1,"codedboard":""}]

в чем проблема?


person jack_the_beast    schedule 14.04.2015    source источник
comment
Пожалуйста, поделитесь выводом Log.d("JSON", "resp: " +response); и обратитесь к stackoverflow.com/questions/8740381/   -  person Giru Bhai    schedule 14.04.2015
comment
вот вывод: resp:[{"roundid":4152,"numberofplayers":1,"dateevent":"2015-04-13 19:45:32.121124+02","playernames":"cat","turn":1,"codedboard":""},{"roundid":4154,"numberofplayers":1,"dateevent":"2015-04-13 20:16:08.845409+02","playernames":"cat","turn":1,"codedboard":""},{"roundid":4155,"numberofplayers":1,"dateevent":"2015-04-13 20:18:22.002411+02","playernames":"cat","turn":1,"codedboard":""}]   -  person jack_the_beast    schedule 14.04.2015


Ответы (2)


Полный выстрел в темноте, но у меня было подобное на парсере RSS. Оказывается, URL-адрес, который я использовал, был HTTP, но был перенаправлен на HTTPS, и я использовал HttpURLConnection вместо HttpsURLConnection.

Хотя я не использовал Android Volley, так что YMMV.

person MCLLC    schedule 14.04.2015

Я, наконец, решил это, проблема в том, что по какой-то причине JSonArrayRequest не принимал параметры POST.

Поэтому я просто вручную добавил параметры к URL-адресу.

person jack_the_beast    schedule 18.04.2015