title: How do I retrieve a JSONObject subfield?
body: <p>I've been looking around for this for a while. I'm working with exchangerate API and I need a bit of help with the json responses.i want to get the date and the <strong>Double</strong> value of <strong>CAD</strong>.</p>
  
  <p>Here is a JSONObject that I have:</p>
  
  <pre><code>{"rates":{"2019-11-27":{"CAD":1.3266418385},
      "2019-11-28":{"CAD":1.3289413903},
      "2019-12-03":{"CAD":1.3320386596},
      "2019-12-02":{"CAD":1.3295835979},
      "2019-11-29":{"CAD":1.3307230013}},
      "start_at":"2019-11-27","base":"USD","end_at":"2019-12-03"}
  </code></pre>
  
  <blockquote>
    <p>My Activity</p>
  </blockquote>
  
  <p>public class ChartActivity extends AppCompatActivity {</p>
  
  <pre><code>    @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_chart);
          new GetServerData(this).execute();
      }
  
      private static class GetServerData extends AsyncTask&lt;Integer, Void, List&lt;BarEntry&gt;&gt; {
          private static final int TIMEOUT = 30000;
          private static final String BASE_URL = "https://api.exchangeratesapi.io/history?start_at" +
                  "=2019-11-27&amp;end_at=2019-12-03&amp;base=USD&amp;symbols=CAD";
          private WeakReference&lt;ChartActivity&gt; activityReference;
  
          GetServerData(ChartActivity context) {
              activityReference = new WeakReference&lt;&gt;(context);
          }
  
          @Override
          protected void onPreExecute() {
              super.onPreExecute();
          }
  
          @Override
          protected List&lt;BarEntry&gt; doInBackground(Integer... integers) {
              List&lt;BarEntry&gt; barEntries = new ArrayList&lt;&gt;();
              OkHttpClient client = new OkHttpClient().newBuilder()
                      .readTimeout(TIMEOUT, TimeUnit.SECONDS)
                      .connectTimeout(TIMEOUT, TimeUnit.SECONDS)
                      .writeTimeout(TIMEOUT, TimeUnit.SECONDS)
                      .retryOnConnectionFailure(true)
                      .build();
              Request request = new Request.Builder()
                      .url(BASE_URL)
                      .build();
              try {
                  Response response = client.newCall(request).execute();
                  Log.d("Response", response.toString());
                  JSONObject object = new JSONObject(Objects.requireNonNull(response.body()).string());
                  JSONObject rates = object.getJSONObject("rates");
                  Iterator&lt;String&gt; iterator = rates.keys();
                  while (iterator.hasNext()) {
                      /* what i should write here to get the date and double values which is in 
                       JSONObject.*/
  
                      //barEntries.add(new BarEntry(int required of date, float required of value ));
                  }
              } catch (IOException | JSONException e) {
                  e.printStackTrace();
                  Log.d("ChartActivity", e.toString());
              }
              return barEntries;
          }
  
          @Override
          protected void onPostExecute(final List&lt;BarEntry&gt; result) {
              final ChartActivity activity = activityReference.get();
              if (activity == null || activity.isFinishing()) {
                  return;
              }
              BarChart barChart = activity.findViewById(R.id.bar_chart);
  
              BarDataSet dataSet = new BarDataSet(result, "Growth");
              dataSet.setColors(ColorTemplate.COLORFUL_COLORS);
              BarData barData = new BarData(dataSet);
              barData.setBarWidth(0.9f);
              barChart.animateY(5000);
              barChart.setData(barData);
              barChart.setFitBars(true);
              Description description = new Description();
              description.setText("Growth rate per week");
              barChart.setDescription(description);
              barChart.invalidate();
  
          }
      }
  }
  </code></pre>
  
  <p>as you see i want to retrieve the data to show a chart 
  any help please!</p>