title: How to parse JSON list or object in C#
body: <p>I have one JSON like:</p>
  
  <p>In success response it is like:</p>
  
  <pre><code>{
    statusCode: "200",
    status: "Success",
    data: [
      {
        empName: "Prashant",
        empCode: 001
      },
      {
        empName: "Jack",
        empCode: 002
      }
    ]
  }
  </code></pre>
  
  <p>and In error response or if there is an exception while processing a request like:</p>
  
  <pre><code>{
    statusCode: "400",
    status: "Fail",
    data: {
      empId: "This field is mandatory"
    }
  }
  </code></pre>
  
  <p>How I can parse the response in both case? Now I am getting an exception while parsing the JSON.</p>
  
  <p>The C# Class I used to parse the response is:</p>
  
  <pre><code>public class Employee
  {
      public string empName { get; set; }
      public int empCode { get; set; }
  }
  
  public class Response
  {
      public string statusCode { get; set; }
      public string status { get; set; }
      public List&lt;Employee&gt; data { get; set; }
  }
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>The exception details:</p>
  
  <blockquote>
    <p>System.InvalidCastException: Specified cast is not valid.</p>
  </blockquote>