You're getting an empty collection because your classes don't match your JSON. I see at least two issues:
First, the outer JSON object has a property called Employees
but the Foo
class you are deserializing into has a property called FooEmployees
. Since the names don't match, your FooEmployees
collection will remain empty. Try adding a [JsonProperty("Employees")]
attribute to the FooEmployees
property like you did elsewhere in your code.
Second, the Employees
collection in the JSON does not actually contain a collection of Employee
objects as you have defined them in your classes. Instead, it contains a collection of objects that each have single property called Employee
which contains an Employee
instance. To fix this, you can do one of the following:
- change your JSON to eliminate the extra layer.
- define a wrapper class (e.g.
EmployeeHolder
) to represent the extra layer in the JSON, and makeFooEmployees
a collection of those. - implement a JSON converter to abstract away the extra layer during deserialization. See Is there a way to deserialize my JSON without using a wrapper class for each item? for more details on this approach.