Array of Generic Objects

Apr 2, 2013 at 4:10 PM
I'm trying to learn more about JSON and need to know how to deserialize an array that includes various objects derived from a base Class. Meaning, if I had a base Class named Employee that had a few common properties and then two other Classes named Manager and Gopher that had other specific properties.... how do you deserialize into the respective object?

Let's say the array included the following objects...

// NOTE: This is not the JSON text; only the object variables in C#.
[ manager1, gopher1, gopher2, manager2, manager3, gopher3 ]

I believe once it is deserialized into an arrary or List<Employee> I could cycle through and check it like....

foreach(Employee eNext in employees)
{
if (eNext is Manager)
{
    // do this...
}
else if(eNext is Gopher)
{
    // do this...
}
}

I've seen where some JSON text includes @type or @class, but not sure how to use appropriately. Any help is appreciated.