title: How do I get a list of Countries, States and Cities from this JSON?
body: <p>I have a JSON that contains the names of Countries, their states and cities of those states. Here is the <a href="https://github.com/sagarshirbhate/Country-State-City-Database/blob/master/Contries.json" rel="nofollow noreferrer">json</a>. </p>
  
  <p>I am able to get all the countries but I can't figure out how to get the states based on the selected country and then cities based on the selected state.</p>
  
  <p>Here is how I got the countries.<code>enter code here</code></p>
  
  <p>First to load the file from assets:</p>
  
  <pre><code>public String loadJSONFromAsset() {
      String json = null;
      try {
          InputStream is = getAssets().open("Contries.json");
          int size = is.available();
          byte[] buffer = new byte[size];
          is.read(buffer);
          is.close();
          json = new String(buffer, "UTF-8");
      } catch (IOException ex) {
          ex.printStackTrace();
          return null;
      }
      return json;
  }
  </code></pre>
  
  <p>Then to load the countries into an ArrayList.</p>
  
  <pre><code>public void loadCountries(String parent, String child, ArrayList&lt;String&gt; listValue)
  {
      try {
  
          JSONObject obj = new JSONObject(loadJSONFromAsset());
          JSONArray m_jArry = obj.getJSONArray(parent);;
          ArrayList&lt;HashMap&lt;String, String&gt;&gt; formList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  
          HashMap&lt;String, String&gt; m_li;
  
        //  listValue = new ArrayList&lt;&gt;();
  
          for (int i = 0; i &lt; m_jArry.length(); i++) {
              JSONObject jo_inside = m_jArry.getJSONObject(i);
  
              listValue.add(jo_inside.getString(child));
          }
  
  
      } catch (JSONException e) {
  
          e.printStackTrace();
      }
  
  
  }
  </code></pre>
  
  <p>Then this line finally:</p>
  
  <pre><code>loadCountries("Countries", "CountryName", countries);
  </code></pre>
  
  <p>After I have selected a country, I want to load its states. maybe something like this:</p>
  
  <pre><code>loadCountries("Pakistan", "StateName", states);
  </code></pre>
  
  <p>and then:</p>
  
  <pre><code>loadCountries("Islamabad Capital Territory", "CityName", cities);
  </code></pre>
  
  <p>Any help is greatly appreciated.</p>