Android volley: Expected BEGIN_ARRAY but was BEGIN_OBJECT

admin

Administrator
Staff member
I am developing Android application where I need to get posts from Wordpress blog (with specific tag).
Code:
JSON API
plugin is installed: <a href="https://wordpress.org/plugins/json-api/" rel="nofollow noreferrer">https://wordpress.org/plugins/json-api/</a>

In my application I use Volley library. I am getting this error:

Code:
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT

My code:

Code:
 String url = " http://christianconcepts.com/api/get_tag_posts/?tag_slug=appcontent ";
        ListView postList;
        List&lt;Object&gt; list;
        Gson gson;
        Map&lt;String,Object&gt; mapPost;
        Map&lt;String,Object&gt; mapTitle;
        String postTitle[];

    StringRequest request = new StringRequest(Request.Method.GET, url, new Response.Listener&lt;String&gt;() {

                @Override
                public void onResponse(String s) {
                    gson = new Gson();
                    list = (List) gson.fromJson(s, List.class); // error line
                    postTitle = new String[list.size()];

                    for(int i=0;i&lt;list.size();++i){

                        mapPost = (Map&lt;String,Object&gt;)list.get(i);
                        mapTitle = (Map&lt;String, Object&gt;) mapPost.get("title");
                        postTitle[i] = (String) mapTitle.get("rendered");
                    }
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError volleyError) {
                    Toast.makeText(getActivity().getApplicationContext(), "Some error occurred", Toast.LENGTH_LONG).show();
                }
            });

            RequestQueue rQueue = Volley.newRequestQueue(myView.getContext());
            rQueue.add(request);

Could someone help me and tell what do I need to change in order to make it work?