title: Get Exchange Rate From Currency Converter API in C#
body: <p>Here is my api call:</p>
  
  <pre><code>https://free.currencyconverterapi.com/api/v6/convert?q=EUR_USD&amp;compact=y
  </code></pre>
  
  <p>I wrote a method that accepts to/from parameters for exchange rates and I successfully get back a result. My problem is parsing that result to get the value. Here is what I have thus far:</p>
  
  <pre><code>public async Task&lt;string&gt; GetExchangeRate(string from, string to)
  {
      //Examples:
      //from = "EUR"
      //to = "USD"
      using (var client = new HttpClient())
      {
          try
          {
              client.BaseAddress = new Uri("https://free.currencyconverterapi.com");
              var response = await client.GetAsync($"/api/v6/convert?q={from}_{to}&amp;compact=y");
              var stringResult = await response.Content.ReadAsStringAsync();
              dynamic data = JObject.Parse(stringResult);
              //data = {"EUR_USD":{"val":1.140661}}
              //I want to return 1.140661
              //EUR_USD is dynamic depending on what from/to is
              return data.?????.val;
          }
          catch (HttpRequestException httpRequestException)
          {
              Console.WriteLine(httpRequestException.StackTrace);
              return "Error calling API. Please do manual lookup.";
          }
      }
  }
  </code></pre>
  
  <p>If my data variable = <code>{"EUR_USD":{"val":1.140661}}</code> where <code>"EUR_USD"</code> is dynamic (It changes pending on what to/from is) then how do I return 1.140661?</p>
  
  <p><strong>ANSWER I USED</strong>
  Here is the code I used based off of @maccettura comment:</p>
  
  <pre><code>var stringResult = await response.Content.ReadAsStringAsync();
  var dictResult = JsonConvert.DeserializeObject&lt;Dictionary&lt;string, Dictionary&lt;string, string&gt;&gt;&gt;(stringResult);
  return dictResult[$"{from}_{to}"]["val"];
  </code></pre>