title: Parsing JSON array in android
body: <p>I have a json response in the format <code>[{id:1, name:a}{id:2, name:b}]</code>. I want to put name values(a, b..) in the spinner. If I select an item in the spinner lets say 'a' I need to get the id value that is 1. How can I do that? Please help me on this. Examples will be helpful.</p>
  
  <pre><code>    createworkorder.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
  
              try {
                  HttpClient httpclient = new DefaultHttpClient();
                  String url = "http://192.168.10.60:8095/tmanager/city?";
                  url = url.replace(" ", "%20");
                  HttpPost httppost = new HttpPost(url);
                  HttpResponse response = httpclient.execute(httppost);
                  HttpEntity entityres = response.getEntity();
                  isX = entityres.getContent();
                  response_string = Utils1.getResponse(isX);
  
              } catch (Exception e) {
                  Log.e("log_tag", "Error in http connection " + e.toString());
                  System.out.println("Error in http connection "
                          + e.toString());
              }
  
              allCities = new ArrayList&lt;String&gt;();
  
              try {
                  cityArray = new JSONArray(response_string);
  
                  for (int i = 0; i &lt; cityArray.length(); i++) {
  
                      JSONObject obj = cityArray.getJSONObject(i);
                      Iterator&lt;String&gt; it = obj.keys();
  
                      String str = it.next().toString().trim();
                      Log.v("str is", str);
  
                      allCities.add(str);
  
                      intent = new Intent(CreateOpenWO.this,
                              CreateWorkOrder.class);
                      startActivity(intent);
  
                  }
  
              } catch (JSONException e) {
                  Log.e("JSON", "There was an error parsing the JSON", e);
              }
  
          }
      });`enter code here`
  </code></pre>