I have an object model that includes an array of longs and I'm deserializing a json string that contains an array using a custom javascript converter and the javascript serializer class.
I thought this would work but it doesn't:
List<long> TheList = new List<long>;
if (dictionary.ContainsKey("TheArray") && dictionary["TheArray"] != null)
{
TheList = serializer.ConvertToType<List<long>>(dictionary["TheArray"]); //bug
TheObject.TheObjectList = (from s in TheList
select Convert.ToInt64(s)).ToList<long>();
}
The error is on the line TheList = serializer.ConvertToType... and the error message is:
Cannot convert object of type 'System.String' to type 'System.Collections.Generic.List`1[System.Int64]'
I also tried this:
var TheStringArray = serializer.ConvertToType<string>(dictionary["TheArray"]);
TheObject.TheObjectList = (from s in TheStringArray.Split(',')
select Convert.ToInt64(s)).ToList<long>();
But then I get this error message:
Type 'System.String' is not supported for deserialization of an array.
What am I missing?
Thanks.