title: How to take name and its code using JSON in Android?
body: <p>I am trying to making weather application. I am new on android.My goal is finding different location's weather on this app. For example, when I choose a "00000.1.17.352"it  will give me Adana but I can not change location because it depends on code. I want to take code depending on name. Here is my JSONparser. </p>
  
  <p><img src="https://i.stack.imgur.com/CbkQ9.png" alt="JSON Values for &quot;name&quot; and &quot;code&quot;"></p>
  
  <p>If I write name to editview, I want to get its code. Here is my layout and java code. </p>
  
  <pre><code>    &lt;EditView
          android:id="@+id/city_field"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textColor="@color/white"
  
          android:layout_alignParentTop="true"
          android:layout_centerHorizontal="true" /&gt;
  
  
      &lt;TextView
          android:id="@+id/code"
          android:textColor="@color/white"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textSize="70sp"
          android:layout_alignParentTop="true"
          android:layout_centerHorizontal="true"
          android:layout_marginTop="85dp"/&gt;
  </code></pre>
  
  <p>There I am fetching city name and city code.</p>
  
  <pre><code>public class CityFetch  {
  
  private String urlString = null;
  public volatile boolean parsingComplete = true;
  private String cityCode = "cityCode";
  private String cityName = "cityName";
  public CityFetch(String url){
      this.urlString = url;
  }
  
   public String getCityCode(){
  
      return cityCode;
  }
  
  public String getCityName(){
  
      return cityName;
  }
  
  
  @SuppressLint("NewApi")
  public void readAndParseJSON(String in) {
      try {
          JSONObject reader = new JSONObject(in);
  
  
          cityCode= reader.getJSONObject("data")
                  .getJSONArray("results").getJSONObject(0)
                  .getJSONArray("cities").getJSONObject(0)
                  .getString("code");
  
          cityName= reader.getJSONObject("data")
                  .getJSONArray("results").getJSONObject(0)
                  .getJSONArray("cities").getJSONObject(0)
                  .getString("name");
  
  
          parsingComplete = false;
  
  
  
      } catch (Exception e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
  }
  public void fetchJSON(){
      Thread thread = new Thread(new Runnable(){
          @Override
          public void run() {
              try {
                  URL url = new URL(urlString);
                  HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                  conn.setReadTimeout(10000 /* milliseconds */);
                  conn.setConnectTimeout(15000 /* milliseconds */);
                  conn.setRequestMethod("GET");
                  conn.setDoInput(true);
                  // Starts the query
                  conn.connect();
                  InputStream stream = conn.getInputStream();
  
                  String data = convertStreamToString(stream);
  
                  readAndParseJSON(data);
                  stream.close();
  
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
      });
  
      thread.start();
  }
  static String convertStreamToString(java.io.InputStream is) {
      java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");
      return s.hasNext() ? s.next() : "";
  }
  }
  </code></pre>
  
  <p>So how can I access "code" when I write name to the editview field? Is it possible? </p>
  
  <p>Thanks for your answers.</p>