I'm receiving a JSON string in C#, like this :
{
"Id": "617723",
"Acronym": "",
"FirstName": "XXXXX",
"LastName": "XXXXX",
"Groupe": {
"Code": "XXXXX",
"Traductions": {
"French": "",
"English": "XXXXX"
}
},
"BusinessUnit": {
"Code": "XXXXX",
"Traductions": {
"French": "",
"English": "XXXXX"
}
},
"Team": {
"Code": null,
"Traductions": {
"French": "",
"English": null
}
},
"Title": {
"Code": null,
"Traductions": {
"French": "",
"English": "XXXXX"
}
},
"Title2": {
"Code": null,
"Traductions": {
"French": "",
"English": null
}
},
"JobCategory": {
"Code": "XXXXX",
"Traductions": {
"French": "",
"English": "XXXXX"
}
},
"PhoneList": [],
"DateHired": "XXXXX",
"DateTerminated": "XXXXX",
"Gender": "XXXXX",
"ManagerId": "XXXXX",
"ManagerAcronym": "XXXXX",
"IsManager": false,
"Email": null,
"CarLicense": null,
"MyTeam": [],
"HomeBase": {
"Code": "XXXXX",
"Traductions": {
"French": "XXXXX",
"English": "XXXXX"
}
},
"Country": {
"Code": "XXXXX",
"Traductions": {
"French": "XXXXXX",
"English": "XXXXX"
}
},
"State": {
"Code": "XXXXX",
"Traductions": {
"French": "XXXXX",
"English": "XXXXX"
}
},
"City": {
"Code": "XXXXX",
"Traductions": {
"French": "XXXXX",
"English": "XXXXX"
}
},
"ShirtSize": "",
"LanguageAddressBook": "XXXXX",
"LanguagePrefered": null,
"Local": null,
"Mailbox": null,
"HomeBusinessUnit": "1",
"JobType": "XXXXXX",
"UnionCode": "",
"ProfessionalTitle": {
"Code": null,
"Traductions": {
"French": "",
"English": null
}
},
"IconEmailActif": true,
"IconSkypeActif": true
}
I want to convert it in a C# Object, so I made my Model like this :
public class UsersJson
{
public string Acronym { get; set; }
public string[] BusinessUnit { get; set; }
public string CarLicense { get; set; }
public string[] City { get; set; }
public string[] Country { get; set; }
public string DateHired { get; set; }
public string DateTerminated { get; set; }
public string Email { get; set; }
public string FirstName { get; set; }
public string Gender { get; set; }
public string[] Groupe { get; set; }
public string[] HomeBase { get; set; }
public string HomeBusinessUnit { get; set; }
public bool IconEmailActif { get; set; }
public bool IconSkypeActif { get; set; }
public string Id { get; set; }
public bool IsManager { get; set; }
public string[] JobCategory { get; set; }
public string JobType { get; set; }
public string LanguageAddressBook { get; set; }
public string LanguagePrefered { get; set; }
public string LastName { get; set; }
public string Local { get; set; }
public string Mailbox { get; set; }
public string ManagerAcronym { get; set; }
public string ManagerId { get; set; }
public string[] MyTeam { get; set; }
public string[] PhoneList { get; set; }
public string[] ProfessionalTitle { get; set; }
public string ShirtSize { get; set; }
public string[] State { get; set; }
public string[] Team { get; set; }
public string[] Title { get; set; }
public string[] Title2 { get; set; }
public string UnionCode { get; set; }
}
When I try to Deserialize it into a List<UsersJson>
, I get the following error :
Cannot deserialize the current JSON object (e.g. {\"name\":\"value\"}) into type 'System.String[]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly. To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object. Path '[0].Groupe.Code', line 1, position 87."
So, how should I declare the property Group
if it's not a string[]
?