1

Closed

Deserialization of array fails

description

When I deserialize the attached JSON using the following class definition:
    public class Job
    {
        public string id { get; set; }
        public string created_at { get; set; }
        public string title { get; set; }
        public string location { get; set; }
        public string type { get; set; }
        public string description { get; set; }
        public string how_to_apply { get; set; }
        public string company { get; set; }
        public string company_url { get; set; }
        public string company_logo { get; set; }
        public string url { get; set; }
    }
I am going to deserialize the array of Jobs, so I call
JSON.ToObject<Job[]>(data, new JSONParameters 
{
    IgnoreCaseOnDeserialize = true, 
    UseExtensions = false, 
    UsingGlobalTypes = false 
});
and the following exception is thrown
Unable to cast object of type 'System.Object[]' to type 'Quality.Json.Performance.Resources.Job[]'.

   at fastJSON.deserializer.ToObject[T](String json)
   at fastJSON.JSON.ToObject[T](String json, JSONParameters param)

file attachments

Closed Jul 15, 2016 at 10:44 AM by MGholam
Fixed in 2.1.17

comments

MGholam wrote Jul 15, 2016 at 10:05 AM

Try this instead (while I get job[] to work):
JSON.ToObject<List<Job>>(data, new JSONParameters 
{
    IgnoreCaseOnDeserialize = true, 
    UseExtensions = false, 
    UsingGlobalTypes = false 
});