Happy New Year :-)

I have the following JSON object:

```
{
\"OutcomeSummaryID\":105,
\"DeliveryDetailsID\":9,
\"AttemptedDeliveryModesIDList\":[1,5],
}

```

And I am using the following method to deserialize it:

```
private void SerializeModel<T>(IDictionary<string, object> dataModel, T myModel)
    {
        Type sourceType = typeof(T);
        foreach (PropertyInfo propInfo in (sourceType.GetProperties()))
        {
            if (dataModel.ContainsKey(propInfo.Name))
            {
                //  if an empty string has been returned don't change the value
                if (dataModel[propInfo.Name].ToNullSafeString() != String.Empty)
                {
                    try
                    {
                        Type localType = propInfo.PropertyType;
                        localType = Nullable.GetUnderlyingType(localType) ?? localType;                            
                        propInfo.SetValue(myModel, Convert.ChangeType(dataModel[propInfo.Name], localType), null);                            
                    }
                    catch (Exception e)
                    {
                        //  ToDo: log serialize value errors
                    }

                }
            }
        }
    }

```

The model definition is:

```
public class DeliveryDetailsView
{
    public int OutcomeSummaryID { get; set; }
    public int DeliveryDetailsID { get; set; }
    public List<int> AttemptedDeliveryModesIDList { get; set; }
}

```

When I run this is get the following exception:

```
System.InvalidCastException was caught
Message=Object must implement IConvertible.

```

This is an extract from a larger project and I have used this method extensively elsewhere but this is the first time with a list as a field and I can see no clean way to resolve this. I could use

```
if (localType.IsCollectionType())

```

but don't know where to proceed after that.(None of the answers from Google seem to fit this situation and most relate to XML).

Thanks in advance.

**UPDATE**

Thanks to @Cube below I now have a partial answer.

```
 if (localType.IsGenericType && localType.GetGenericTypeDefinition().Equals(typeof(List<>)))
{   
    Type localListType = localType.GetGenericArguments()[0];
    if (localListType.Equals(typeof(int)))
    {
        IDictionary<string, object> dataItem = (Dictionary<string, object>)dataModel[propInfo.Name];
        List<int> tempList = new List<int>();
        foreach (var item in dataItem)
        {
            tempList.Add((int)item.Value);
        }
        propInfo.SetValue(perinatalModel, tempList,  null);
    }
}

```

... However, all attempts to convert the JSON array to a List have failed. I have also attempted

```
List<int> tempList = (List<int>)dataModel[propInfo.Name];

```

Both throw the exception

```
Unable to cast object of type 'System.Object[]' ...

```

Any further thoughts

Thanks