title: Deserialize part of json to datatable in C# using JSON.NET where the key is dynamic
body: <p>I don't think the marked duplication is correct as I don't have any sort of root key to hang off, the duplicate example given had the static key "devices" where as my example doesn't have that.</p>
  
  <p>How can you use JSON.Net to deserialize a part of a json when the key is dynamic, so for example</p>
  
  <pre><code>{"USD_GBP":{"val":0.777803}}
  </code></pre>
  
  <p>Or</p>
  
  <pre><code>{"USD_EUR":{"val":0.863705}}
  </code></pre>
  
  <p>My nonsense attempt looks like this (cut down version):</p>
  
  <pre><code>public class DeserializeFC
  {
      public Dictionary&lt;string, double&gt; jsonName { get; set; }
  }
  
  
  public void run() 
  {
      DataTable outputData = new DataTable();
      outputData.Columns.Add("timestamp", typeof(System.String));
      outputData.Columns.Add("basecurrency", typeof(System.String));
      outputData.Columns.Add("currency", typeof(System.String));
      outputData.Columns.Add("rate", typeof(System.Decimal));
  
      using (var httpClient = new HttpClient())
      {   
          httpClient.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36");
          var response = httpClient.GetStringAsync(new Uri(fullURL)).Result;        
          string jsonName = loadBaseCurr + "_" + loadCurrency;
          var result3 = JsonConvert.DeserializeObject&lt;DeserializeFC&gt;(response);
  
          foreach (KeyValuePair&lt;string, double&gt; entry3 in result3.jsonName)
          {
              outputData.Rows.Add(DateTime.Now, loadBaseCurr, loadCurrency, entry3.Value);
          }
      } 
  }
  </code></pre>
  
  <p>This is a followup to this question:
  <a href="https://stackoverflow.com/questions/51743753/deserialize-part-of-json-to-datatable-in-c-sharp-using-json-net/51743943#51743943">Deserialize part of json to datatable in C# using JSON.NET</a></p>
  
  <p>The code which worked for me in the end was:</p>
  
  <pre><code>string jsonName = loadBaseCurr + "_" + loadCurrency;
                          var result3 = JObject.Parse(response);
                          var nested = result3[jsonName].ToObject&lt;Dictionary&lt;string, decimal&gt;&gt;(); 
                          foreach (var entry3 in nested)
                          {
                              outputData.Rows.Add(DateTime.Now, loadBaseCurr, loadCurrency, entry3.Value);
                          }
  </code></pre>