0

json with int key value

I've been stuck, to call json like this to android studio using volley, I've never done this before

1 Answers1

0

According to this json with int key value you are

receiving jsonArray instead of jsonObject

so you have to

send the request of JsonArray with volley

then the request will return jsonArray then you can get your string like this.

    JsonArrayRequest jsonArrayRequest = new JsonArrayRequest("url", new Response.Listener<JSONArray>() {
        @Override
        public void onResponse(JSONArray response)
        {
            try
            {
                for (int i=0;i<response.length();i++)
                {
                    JSONArray jsonArray = response.getJSONArray(i);
                    for (int j=0;j<jsonArray.length();j++)
                    {
                        String yourString = jsonArray.getString(j);
                        // you can convert it into int as per your requirement
                    }
                }
            } catch (JSONException e)
            {
                e.printStackTrace();
            }
        }
    },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error)
                {

                }
            });
Himanshu itmca
  • 395
  • 5
  • 22