org.json.JSONException: Value {“storeid0”:[“1535”],“storeid1”:[“1862”]} at idddsss of type org.json.JSONObject cannot be converted to JSONArray

I am getting this response from my api


this is the code that I am using to get response from server and save all storeids in an array:

public ArrayList<String> tripItems = new ArrayList<>();
    private void getAllStoreIds(String user_id){

        String url = Baseurl.getCartDetails+"?user_id="+user_id;

        StringRequest postStringRequest = new StringRequest(Request.Method.POST, url,
                new Response.Listener<String>() {
                    public void onResponse(String response) {
                        Log.d(TAG, "ResponseCheck :" + response);
                        try {
                            JSONObject jsonObject = new JSONObject(response);
                            JSONArray json = jsonObject.getJSONArray("idddsss");
                            if(json.length ()> 0){
                                for(int countItem = 0;countItem<json.length();countItem++){
                                    JSONObject o = json.getJSONObject(countItem);

                                if (!tripItems.equals(null)) {
                                    for (int i = 0; i < tripItems.size(); i++) {
                                        Toast.makeText(myContext, tripItems.get(i), Toast.LENGTH_SHORT).show();

                        } catch (JSONException e) {
                            Toast.makeText(myContext, e.getMessage()+ "Error", Toast.LENGTH_SHORT).show();
                }, new Response.ErrorListener() {
            public void onErrorResponse(VolleyError error) {
                Toast.makeText(myContext, error.getCause().toString(), Toast.LENGTH_SHORT).show();

But whenever i run the code i got following error, I don’t know why, I have parsed my code to JSONObject first and then to JSONArray and in loop I am parsing it to JSONObject again.

W/System.err: org.json.JSONException: Value {"storeid0":["1535"],"storeid1":["1862"]} at idddsss of type org.json.JSONObject cannot be converted to JSONArray
W/System.err:     at org.json.JSON.typeMismatch(
        at org.json.JSONObject.getJSONArray(
        at com.paysano.Fragment.Payment_fragment$6.onResponse(
        at com.paysano.Fragment.Payment_fragment$6.onResponse(
        at android.os.Handler.handleCallback(
        at android.os.Handler.dispatchMessage(
        at android.os.Looper.loop(
        at java.lang.reflect.Method.invoke(Native Method)
W/System.err:     at$


idddsss is object, so use getJSONObject instead getJSONArray

JSONObject objIdddsss = jsonObject.getJSONObject("idddsss");
JSONArray jsonArray = objIdddsss.getJSONArray("storeid0");
Log.v("ANS", objIdddsss.toString());
Log.v("ANS", jsonArray.toString());

Source: stackoverflow