title: JSON Deserialization of two objects using one JSON message with Json.NET C#
body: <p>I am using ASP.Net MVC and JSON.Net API.
  I would like to deserialize two objects, let's say: CustomerOrderHeader and a CustomerOrderLines collection.
  I have the JSON in the jsonString variable:</p>
  
  <pre><code> {
      "customerOrderHeader": {
          "OrderNumber": "",
          "CustomerName": "",
          "Reference": "",
          "ShippingDate": "",
          "CurrencyId": "0",
          "LanguageId": "0",
          "DaLine1": "",
          "DaLine2": "",
          "DaCity": "",
          "DaPostalCode": "",
          "DaState": "",
          "DaCountry": "",
          "BaLine1": "",
          "BaLine2": "",
          "BaCity": "",
          "BaPostalCode": "",
          "BaState": "",
          "BaCountry": "",
          "Notes": ""
      },
      "customerOderLinesModel": [
          {
              "Num": "10",
              "PartNumber": "Inventory1",
              "Description": "aasss",
              "OrderedQuantity": "0",
              "UoM": "cm",
              "SalesPrice": "123.0000",
              "Amount": "0.0000",
              "LineStatus": "Draft",
              "ConfirmedShippingDate": "",
              "ReservedQuantity": "0",
              "DeliveredQuantity": "0",
              "RemainingQuantity": "0"
          }
      ]
  }
  </code></pre>
  
  <p>And I have the Classes:</p>
  
  <pre><code>CustomerOrderModel {
  
          public string BillingAddress
          { get; set; }
  
          public string ShippingAddress
          { get; set; }
  
          [DisplayName("Customer name*:")]
          [Required]
          public string CustomerName
          { get; set; }
  
          [DisplayName("Order Number :")]
          public long? OrderNumber
          { get; set; }
  
          [DisplayName("Order Status :")]
          public int OrderStatus
          { get; set; }
  
          public string OrderStatusName 
          { get; set; }
  
          [DisplayName("Shipping Date :")]
          public DateTime? ShippingDate
          { get; set; }
  
          public bool IsDefaultda
          { get; set; }  
  
          [DisplayName("Total Amount :")]
          public decimal TotalAmount
          { get; set; }
  
          [DisplayName("Address Line 1 :")]
          public string DaLine1
          { get; set; }
  
          [DisplayName("Address Line 2 :")]
          public string DaLine2
          { get; set; }
  
          [DisplayName("City :")]
          public string DaCity
          { get; set; }
  
          [DisplayName("Postal Code :")]
          public string DaPostalCode
          { get; set; }
  
          [DisplayName("State :")]
          public string DaState
          { get; set; }
  
          [DisplayName("Country :")]
          public string DaCountry
          { get; set; }
  
          [DisplayName("Address Line 1 :")]
          public string BaLine1
          { get; set; }
  
          [DisplayName("Address Line 2 :")]
          public string BaLine2
          { get; set; }
  
          [DisplayName("City :")]
          public string BaCity
          { get; set; }
  
          [DisplayName("Postal Code :")]
          public string BaPostalCode
          { get; set; }
  
         ...
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>public class CustomerOrderLineModel
      {
          public CustomerOrderLineModel()
          {
          }
  
          public String OrderNumber { get; set; }
          public String Num { get; set; }
  
          public String PartNumber { get; set; }
          public String Description { get; set; }
          public String OrderedQuantity { get; set; }
          public String UoM { get; set; }
          public String SalesPrice { get; set; }
          public String Amount { get; set; }
          public String LineStatus { get; set; }
          public DateTime? ConfirmedShippingDate { get; set; }
          public String ReservedQuantity { get; set; }
          public String DeliveredQuantity { get; set; }
          public String RemainingQuantity { get; set; }
  
  
      }
  </code></pre>
  
  <p>What I just want to do is get the JSON and pass to this classes:</p>
  
  <pre><code>  JObject jObject = JObject.Parse(jsonString);
    JToken jToken =  jObject.SelectToken("customerOrderHeader");
  </code></pre>
  
  <p>Now I would like to make this jToken PassTo CustomerOrderModel class,
  Something like:</p>
  
  <pre><code> CustomerOrderModel customerOrderModel = (CustomerOrderModel) jObject.SelectToken("customerOrderHeader");
  </code></pre>
  
  <p>the same to the collection of CustomerOrderLineModels:</p>
  
  <pre><code>List&lt;CustomerOrderLineModel&gt; customerOrderLines = (List&lt;CustomerOrderLineModel&gt;) jObject.SelectToken("customerOderLinesModel");
  </code></pre>
  
  <p>But I can't do this, because it returns string.</p>
  
  <p>thanks,</p>
  
  <p>Tito</p>