title: How to deserialize json object in C#
body: <p>I am trying to deserialize the json string to a c# object.</p>
  
  <pre><code>string str ="[{ \"foo\" : \"A\" , \"bar\" : \"B\"}, { \"foo\" : \"C\" , \"bar\" : \"D\"}]";
  
  public Class Example
  {
    public string foo { get; set; }
    public string bar { get; set; }
  }
  
  JavaScriptSerializer Js = new JavaScriptSerializer();
  Example[] ex = (Example[]) Js.DeserializeObject(str);
  </code></pre>
  
  <p>But I am getting an <code>InvalidCast Exception</code>. What am I doing wrong?</p>