title: Deserialize nested json objects into c# objects
body: <p>I have the following Json response:</p>
  
  <pre><code>{
    "Customers": [
      {
        "Customer": {
          "Address": {
            "City": "Stockholm",
            "PostalCode": "10123"
          },
          "Classifications": [
            "LoyaltyProgram",
            "Returning",
            "VeryImportant"
          ],
          "FirstName": "Peter",
          "LastName": "Centers",
          "Passport": {
            "Expiration": "2019-01-14",
            "Number": "1564931321655"
          },
        },
        "FirstName": "Peter",
        "LastName": "Centers",
        "Reservation": {
          "AdultCount": 2,
          "AssignedSpaceId": "03f59360-8644-4e29-927a-ad85a6514466",
        },
        "RoomNumber": "302"
      },
    ]
  }
  </code></pre>
  
  <p>I have the following classes for every Customer:</p>
  
  <pre><code>public class CustomerDto
  {
      public string FirstName { get; set; }
      public string LastName { get; set; }
      public List&lt;string&gt; Classifications { get; set; }
      public PassportDto Passport { get; set; }
      public AddressDto Address { get; set; }
  }
  
  public class AddressDto
  {
      public string City { get; set; }
      public string PostalCode { get; set; }
  }
  
  public class PassportDto
  {
      public string Expiration { get; set; }
      public string Number { get; set; }
  }
  </code></pre>
  
  <p>from this I use Json.Net and the following code from one of my methods (extract) where customers below is the response:</p>
  
  <pre><code>var jsonCustomers = JObject.Parse(customers)["Customers"].Children().ToList();
  IList&lt;CustomerDto&gt; customerList = new List&lt;CustomerDto&gt;();
  foreach (var item in jsonCustomers) {
      customerList.Add(item.ToObject&lt;CustomerDto&gt;());
  }
  </code></pre>
  
  <p>All the values in CustomerDto are filled except for Address and Passport, that are null, and I can't figure out why. </p>