title: How do Deserialize XML to json and json to c# classes?
body: <pre><code>   // This is my xml data I am trying to map this to my .net classes. By converting XML to json and json back to C# classes.
  
         string xml = @"  &lt;ReportTemplate&gt;
        &lt;Page Id='1' LayoutId='1'&gt;
          &lt;Section Id='1'&gt;
            &lt;Body&gt;TEststindfgdfgf&lt;/Body&gt;
          &lt;/Section&gt;`enter code here`
          &lt;Section Id='2'&gt;
            &lt;Content Id='9834ebcd0e9537c315a42cf0d8ed32745f89827c' Type='News'&gt;&lt;/Content&gt;
          &lt;Content Id='9834ebcd0e9537c315a42cf0d8ed32745f89827c' Type='News' &gt;&lt;/Content&gt;
          &lt;/Section&gt;
          &lt;Section Id='3'&gt;
             &lt;Content Id='9834ebcd0e9537c315a42cf0d8ed32745f89827c' Type='News'&gt;&lt;/Content&gt;
          &lt;/Section&gt;
        &lt;/Page&gt;
        &lt;Page Id='2' LayoutId='1'&gt;
          &lt;Section Id='1'&gt;
             &lt;Content Id='9834ebcd0e9537c315a42cf0d8ed32745f89827c' Type='News'&gt;&lt;/Content&gt;
            &lt;Content Id='9834ebcd0e9537c315a42cf0d8ed32745f89827c' Type='News'&gt;&lt;/Content&gt;
          &lt;/Section&gt;
          &lt;Section Id='2'&gt;
             &lt;Content Id='9834ebcd0e9537c315a42cf0d8ed32745f89827c' Type='News'&gt;&lt;/Content&gt;
          &lt;/Section&gt;
          &lt;Section Id='3'&gt;
            &lt;Body&gt;dfgdgggf;&lt;/Body&gt;
          &lt;/Section&gt;
        &lt;/Page&gt;
      &lt;/ReportTemplate&gt;";
  
  
          public class ReportTemplate
          {
                public List&lt;Page&gt; Page { get; set; }
          }
          public class Page
          {
              public string Id { get; set; }
              public string LayoutId { get; set; }
              public List&lt;Section&gt; Section { get; set; }
          }
  
          public class Section
          {
              public string Id { get; set; }
              public string Body { get; set; }
              public List&lt;Content&gt; Content { get; set; }
          }
          public class Content
          {
              public string Id { get; set; }
              public string Type { get; set; }
  
          }
  
  
  
  var xmldoc = new XmlDocument();
  xmldoc.LoadXml(xml);
  var json = JsonConvert.SerializeXmlNode(xmldoc,Newtonsoft.Json.Formatting.Indented, true);
  var obj = JsonConvert.DeserializeObject&lt;ReportTemplate&gt;(Regex.Replace(json, "(?&lt;=\")(@)(?!.*\":\\s )", string.Empty, RegexOptions.IgnoreCase));
  </code></pre>
  
  <p>//This is the error that i am getting</p>
  
  <blockquote>
    <p>Newtonsoft.Json.JsonSerializationException: 'Cannot deserialize the
    current JSON object (e.g. {"name":"value"}) into type
    'System.Collections.Generic.List`1[LintoXML.Program+Content]' because
    the type requires a JSON array (e.g. [1,2,3]) to deserialize
    correctly. To fix this error either change the JSON to a JSON array
    (e.g. [1,2,3]) or change the deserialized type so that it is a normal
    .NET type (e.g. not a primitive type like integer, not a collection
    type like an array or List) that can be deserialized from a JSON
    object. JsonObjectAttribute can also be added to the type to force it
    to deserialize from a JSON object. Path
    'Page[0].Section[2].Content.Id', line 27, position 17.'</p>
  </blockquote>