Syed Abbas Zakir Hussain Syed Abbas Zakir Hussain - 1 month ago 5
C# Question

Cannot deserialize the current JSON array

I execute a query from linq that gives me a list of columns
Here's the query:

var userList = context.Users.Where(x => x.UserFirstName.Contains(value.ToString()) && x.UserAccessLevel == (int)AuthUser.AuthUserUserType.Manager)
.Select(x =>new UserGridDetails(){ UserFirstName = x.UserFirstName, UserLastName = x.UserLastName, UserEmailAddress = x.UserEmailAddress})

output = JsonConvert.SerializeObject(userList);

Here's the JSON Data from the query


I'm trying to deserialize this data into a C# class object which has the following class

public class UserJsonWrapper
public List<UserGridDetails> UserGridDetailses { get; set; }


public class UserGridDetails
public string UserFirstName { get; set; }
public string UserLastName { get; set; }
public string UserEmailAddress { get; set; }

Here's the deserialize code

UserJsonWrapper jsonToDataTable = JsonConvert.DeserializeObject<UserJsonWrapper>(value);

Rob Rob

Get rid of the wrapper. You're given an array, not an object containing an array as a property.

var jsonToDataTable = JsonConvert.DeserializeObject<List<UserGridDetails>>(value);