0

I'm trying to retrieve a jsonarray from a url using Volley. the problem is that I get

JsonException end of input at character 0

the code is the following:

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);

I was thinking that the problem was in wrong parameters. but I tried with a simple string request:

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 
            }
        };

and it's actually returning the json correctly. for example:

[{"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":""}]

what's the problem here?

2
  • 1
    Please Share output of Log.d("JSON", "resp: " +response); And refer stackoverflow.com/questions/8740381/… Commented Apr 14, 2015 at 12:42
  • here is the output: 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":""}] Commented Apr 14, 2015 at 12:49

2 Answers 2

0

Total shot in the dark, but I had similar occur on an RSS parser. It turns out the URL I was using was HTTP, but redirected to HTTPS and I was using an HttpURLConnection instead of HttpsURLConnection.

Though, I wasn't using Android Volley so YMMV.

Sign up to request clarification or add additional context in comments.

Comments

0

I finally solved this, the problem here is that for some reason JSonArrayRequest was not taking the POST parameters.

So I just manually appended the parameters to the url

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.