title: How do I deserialize an array of objects with varying names?
body: <p>In a Windows Phone app using C#, I am trying to deserialize some JSON with the following structure:</p>
  
  <pre><code>[ { "kite" : { "supplier" : "ABC",
          "currency" : "GBP",
          "cost" : "7.98"
        } },
    { "puzzle" : { "supplier" : "DEF",
          "currency" : "USD",
          "cost" : "7.98"
        } },
    { "ball" : { "supplier" : "DEF",
          "currency" : "USD",
          "cost" : "5.49"
        } }
  ]
  </code></pre>
  
  <p>This is a list of toys in which the names of the toys (kite, puzzle, ball) are not known in advance. I don't have any control over the format of the JSON.</p>
  
  <p>Using json2csharp.com I get the following classes:</p>
  
  <pre><code>public class Kite
  {
      public string supplier { get; set; }
      public string currency { get; set; }
      public string cost { get; set; }
  }
  
  public class Puzzle
  ...
  
  public class Ball
  ...
  
  public class RootObject
  {
      public Kite kite { get; set; }
      public Puzzle puzzle { get; set; }
      public Ball ball { get; set; }
  }
  </code></pre>
  
  <p>This looks to me like an array of "toy" objects but I don't know what approach to take when deserializing this.</p>
  
  <p>The only code that I have had work is the basic:</p>
  
  <pre><code>var root = JsonConvert.DeserializeObject(rawJSON);
  </code></pre>
  
  <p>I thought something like the following might work, but I would lose the name of the toy if it worked (and it doesn't):</p>
  
  <pre><code>public class Toy
  {
      public string supplier { get; set; }
      public string currency { get; set; }
      public string cost { get; set; }
  }
  List&lt;Toy&gt; toyList = (List&lt;Toy&gt;) JsonConvert.DeserializeObject(rawJSON, typeof(List&lt;Toy&gt;));
  </code></pre>
  
  <p>Any suggestions please?</p>