У меня есть такой JSON:
{"success":true,"totalCount":7,"data":{"areagrafer":[],"login":"user123","name":"user","description":null,"roles":[],"id":1190740029004,"road":null},"settings":null,"type":null,"model_name":null}
Есть классы:
public class Data
{
public long[] Areagrafer { get; set; }
public string Login { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string[] Roles { get; set; }
public long Id { get; set; }
public int? Road { get; set; }
}
public class ResponseRootSingle<T>
{
public bool Success { get; set; }
public int TotalCount { get; set; }
public T Data { get; set; }
}
Когда я пытаюсь распарсить вот такой JSON:
{"success":true,"totalCount":1,"data":["No user with id = 1190740029003"],"settings":null,"type":null,"model_name":null}
var root = JsonConvert.DeserializeObject<ResponseRootSingle<Data>>(json);
То получаю ошибку:
System.Exception: 'Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'Data' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly. To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.
Как мне сделать так, чтобы поле Data была null, вместо исключения?
"data":["No user with id = 1190740029003"],
- это массив из одного элемента?Data
?