title: Android - populating list from jsonarray using volley
body: <p>My app supposedly to send a source and a destination as parameters to get the fastest bus route and then send them back as an array.
  I want to make a list from a json array using volley. Here is an example of my array output.</p>
  
  <pre><code>{  
     "arrayrute":[  
        "Halte LIK",
        "Halte Kampoeng Semarang",
        "Halte Kaligawe 2",
        "Halte Pasar Kobong",
        "Halte Kota Lama"
     ]
  }
  </code></pre>
  
  <p>How am I supposedly to make a list from it? Usually a json array from a database would have it's row name before the variable so I just have to use <code>list.set_id(jsonobject.getString("id"))</code> or <code>list.set_id(jsonobject.optString("id"))</code></p>
  
  <p>Here's my java code to get the array</p>
  
  <pre><code>private void getData() {
          //Creating a string request
          asal = spin_dari.getSelectedItem().toString().trim();
          tujuan = spin_ke.getSelectedItem().toString().trim();
  
          StringRequest stringRequest = new StringRequest(Request.Method.GET, DIRECTION_URL,
                  new Response.Listener&lt;String&gt;() {
                      @Override
                      public void onResponse(String response) {
                          JSONObject j = null;
                          try {
                              //Parsing the fetched Json String to JSON Object
                              j = new JSONObject(response);
  
                              //Storing the Array of JSON String to our JSON Array
                              results = j.getJSONArray("arrayrute");
  
                              //Calling method getStudents to get the students from the JSON Array
                              getdireksi(results);
                              //dirlist.add(results .toString());
                          } catch (JSONException e) {
                              e.printStackTrace();
                          }
                          adaptdir.notifyDataSetChanged();
                      }
                  },
                  new Response.ErrorListener() {
                      @Override
                      public void onErrorResponse(VolleyError error) {
  
                      }
                  })
          {
              @Override
              protected Map&lt;String,String&gt; getParams(){
                  Map&lt;String,String&gt; params = new HashMap&lt;String, String&gt;();
                  params.put(KEY_ASAL,asal);
                  params.put(KEY_TUJUAN,tujuan);
                  return params;
              }
          };
  
          //Creating a request queue
          RequestQueue requestQueue = Volley.newRequestQueue(this);
  
          //Adding request to the queue
          requestQueue.add(stringRequest);
      }
  
      private void getdireksi(JSONArray j) {
          //Traversing through all the items in the json array
          for (int i = 0; i &lt; j.length(); i++) {
              try {
                  //Getting json object
                  JSONObject json = j.getJSONObject(i);
  
                  //Adding the name of the student to array list
                  dirlist.add(json.toString());
              } catch (JSONException e) {
                  e.printStackTrace();
              }
          }
      }
  </code></pre>