I'm a little stumped on this one. Everything I do to check this out says it is a valid Json array, but JsonConvert.Deserialize says it is an object. Can someone point out what I'm doing wrong?
Code to replicate:
var data = "[{\"User\": {\"Identifier\": \"24233\",\"DisplayName\": \"Commerce Test Student\",\"EmailAddress\": \"email@email.ca\",\"OrgDefinedId\": \"UniqueId1\",\"ProfileBadgeUrl\": null,\"ProfileIdentifier\": \"zzz123\"},\"Role\": {\"Id\": 153,\"Code\": null,\"Name\": \"Commerce Student\"}}]";
var items = JsonConvert.DeserializeObject<List<T>>(data);
Where T is an object that matches the format below:
public class OrgUnitUser
{
public User User { get; set; }
public RoleInfo Role { get; set; }
}
public class User
{
public string Identifier { get; set; }
public string DisplayName { get; set; }
public string EmailAddress { get; set; }
public string OrgDefinedId { get; set; }
public string ProfileBadgeUrl { get; set; }
public string ProfileIdentifier { get; set; }
}
public class RoleInfo
{
public int Id { get; set; }
public string Code { get; set; }
public string Name { get; set; }
}
It results in an error
Newtonsoft.Json.JsonSerializationException: Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[CoverPages.Models.D2L.OrgUnitUser]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
Any/all help is appreciated!