0
est-il possible de désérialiser une liste d'objets complexes à une liste de type savoir: EX:Désérialisation de la liste des objets complexes à la liste exacte de type
public class Employee
{
public string EmployeeNumber { get; set; }
public string AccountName { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string PreferredName { get; set; }
public string Title { get; set; }
}
c'est l'objet sur lequel je aimer désérialiser.
voici comment je l'ai essayé :
var x = JsonConvert.DeserializeObject<List<Dictionary<string, IList<Employee>>>>(_content);
var x = JsonConvert.DeserializeObject<List<Dictionary<string, Employee>>>(_content);
var x = JsonConvert.DeserializeObject<List<Dictionary<string, Employee[]>>>(_content);
mais je reçois cette exception
"ExceptionMessage": "Error converting value 37326 to type 'System.Collections.Generic.IList`1[Ubisoft.ECM.Events.Business.Providers.EmployeeProvider.Empoyee]'. Path '[0].EmployeeNumber', line 1, position 24.",
L'exception intérieure:
"InnerException": {
"Message": "An error has occurred.",
"ExceptionMessage": "Could not cast or convert from System.Int64 to System.Collections.Generic.IList`1[Ubisoft.ECM.Events.Business.Providers.EmployeeProvider.Employee].",
"ExceptionType": "System.ArgumentException",
"StackTrace": " at Newtonsoft.Json.Utilities.ConvertUtils.EnsureTypeAssignable(Object value, Type initialType, Type targetType)\r\n at Newtonsoft.Json.Utilities.ConvertUtils.ConvertOrCast(Object initialValue, CultureInfo culture, Type targetType)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType)"
}
Merci. Pour désérialiser à List, j'ai dû faire référence à System.Web.Script.Serialization.
Avez-vous vérifié cela? http://stackoverflow.com/questions/7895105/deserialize-json-with-c-sharp –
ouais, ça marche bien, merci –