title: Newtonsoft.Json.JsonSerializationException: Error converting value, Could not cast or convert from System.String to DashBoard.DashboardReport
body: <p>I have written the code to deserialize JSON from String to Class(DashBoardReport) Object type,but it gives me below exception, I checked out my JSON structure, it is a valid JSON structure and also it is matching with the DashBoardReport Class structure, so I don't understand why its giving me the cast related exception,please help.   </p>
  
  <p><strong>Complete Exception:</strong></p>
  
  <pre><code>Newtonsoft.Json.JsonSerializationException: Error converting value "{"Company":"Shyamlal Bros","VoucherType":"PurcOrder","Interval":null,"CurrentPeriodSummary":{"StartDate":"20170401","EndDate":"20170430","Amount":2459250.0,"Monthlygross":0.0},"PreviousPeriodSummary":{"StartDate":null,"EndDate":null,"Amount":0.0,"Monthlygross":0.0},"CurrentPeriodNetAmount":" ","CurrentPeriodDetails":[{"StartDate":"1-Apr-2017","EndDate":"30-Apr-2017","Amount":2459250.0,"Monthlygross":0.0}],"PreviousPeriodDetails":[],"GrowthIndicator":null,"Growth":0.0,"GroupByReport":null,"Error":null}" to type 'DashBoard.DashboardReport'. Path '', line 1, position 570. ---&gt; System.ArgumentException: Could not cast or convert from System.String to DashBoard.DashboardReport.
  </code></pre>
  
  <p><strong>Code For Deserialization</strong>:</p>
  
  <pre><code>string json="{\"Company\":\"Shyamlal Bros\",\"VoucherType\":\"PurcOrder\",\"Interval\":null,\"CurrentPeriodSummary\":{\"StartDate\":\"20170401\",\"EndDate\":\"20170430\",\"Amount\":2459250.0,\"Monthlygross\":0.0},\"PreviousPeriodSummary\":{\"StartDate\":null,\"EndDate\":null,\"Amount\":0.0,\"Monthlygross\":0.0},\"CurrentPeriodNetAmount\":\"\",\"CurrentPeriodDetails\":[{\"StartDate\":\"1-Apr-2017\",\"EndDate\":\"30-Apr-2017\",\"Amount\":2459250.0,\"Monthlygross\":0.0}],\"PreviousPeriodDetails\":[],\"GrowthIndicator\":null,\"Growth\":0.0,\"GroupByReport\":null,\"Error\":null}";
   DashboardReport r=JsonConvert.DeserializeObject&lt;DashboardReport&gt;(json);    
   string jsonMonth = JsonConvert.SerializeObject(r);
   Console.WriteLine(jsonMonth);
  </code></pre>
  
  <p><strong>Beutified JSON Structure i.e. to be deserialized:</strong></p>
  
  <pre><code>{
    "Company": "Shyamlal Bros",
    "VoucherType": "PurcOrder",
    "Interval": null,
    "CurrentPeriodSummary": {
      "StartDate": "20170401",
      "EndDate": "20170430",
      "Amount": 2459250,
      "Monthlygross": 0
    },
    "PreviousPeriodSummary": {
      "StartDate": null,
      "EndDate": null,
      "Amount": 0,
      "Monthlygross": 0
    },
    "CurrentPeriodNetAmount": " ",
    "CurrentPeriodDetails": [
      {
        "StartDate": "1-Apr-2017",
        "EndDate": "30-Apr-2017",
        "Amount": 2459250,
        "Monthlygross": 0
      }
    ],
    "PreviousPeriodDetails": [],
    "GrowthIndicator": null,
    "Growth": 0,
    "GroupByReport": null,
    "Error": null
  }
  </code></pre>
  
  <p><strong>DashboardReport Class structure:</strong></p>
  
  <pre><code>public class DashboardReport:ITallyReport
      {
  
          private string company;
          private string voucherType;
          private string interval;
          private string error;
  
          private DashboardReportElement currentPeriodSummary;
          private string currentPeriodNetAmount;
          private DashboardReportElement previousPeriodSummary;
          private DashboardReportElement[] currentPeriodDetails;
          private DashboardReportElement[] previousPeriodDetails;
  
          public DashboardReport()
          {
              currentPeriodSummary = new DashboardReportElement();
              previousPeriodSummary = new DashboardReportElement();
              currentPeriodDetails = new DashboardReportElement[] { };
              previousPeriodDetails = new DashboardReportElement[] { };
  
          }
  
          public string Company
          {
              get
              {
                  return company;
              }
  
              set
              {
                  company = value;
              }
          }
  
          public string VoucherType
          {
              get
              {
                  return voucherType;
              }
  
              set
              {
                  voucherType = value;
              }
          }
  
          public string Interval
          {
              get
              {
                  return interval;
              }
  
              set
              {
                  interval = value;
              }
          }
  
          public DashboardReportElement CurrentPeriodSummary
          {
              get
              {
                  return currentPeriodSummary;
              }
  
              set
              {
                  currentPeriodSummary = value;
              }
          }
  
          public DashboardReportElement PreviousPeriodSummary
          {
              get
              {
                  return previousPeriodSummary;
              }
  
              set
              {
                  previousPeriodSummary = value;
              }
          }
  
          public string CurrentPeriodNetAmount { get =&gt; currentPeriodNetAmount; set =&gt; currentPeriodNetAmount = value; }
  
          public DashboardReportElement[] CurrentPeriodDetails
          {
              get
              {
                  return currentPeriodDetails;
              }
  
              set
              {
                  currentPeriodDetails = value;
              }
          }
  
          public DashboardReportElement[] PreviousPeriodDetails
          {
              get
              {
                  return previousPeriodDetails;
              }
  
              set
              {
                  previousPeriodDetails = value;
              }
          }
  
          public string GrowthIndicator { get; set; }
  
          public double Growth { get; set; }
  
          public DashboardGroupByReport GroupByReport { get; set; }
          public string Error { get =&gt; error; set =&gt; error = value; }
  
  
  
  
          //public ReportElement[] Data { get; set; }
          //public string GroupBy { get; set; }
  
  
          public string ToJson()
          {
              return JsonConvert.SerializeObject(this);
  
          }
      }
  </code></pre>
  
  <p><strong>Structure of DashBoardReportElement Class:</strong></p>
  
  <pre><code> public class DashboardReportElement
      {
          private string startDate;
  
          private string endDate;
  
          private double amount;
  
          private double monthlygross;
  
          public DashboardReportElement()
          {
  
          }
          public string StartDate
          {
              get
              {
                  return startDate;
              }
  
              set
              {
                  startDate = value;
              }
          }
  
          public string EndDate
          {
              get
              {
                  return endDate;
              }
  
              set
              {
                  endDate = value;
              }
          }
  
          public Double Amount
          {
              get
              {
                  return amount;
              }
  
              set
              {
                  amount = value;
              }
          }
  
          public double Monthlygross { get =&gt; monthlygross; set =&gt; monthlygross = value; }
      }
  </code></pre>