Zee
Zee

Reputation: 642

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})
                        .ToList();

                output = JsonConvert.SerializeObject(userList);

Here's the JSON Data from the query

[{"UserFirstName":"Manager3","UserLastName":"ManagerLastName","UserEmailAddress":"[email protected]"}]

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);

Upvotes: 0

Views: 70

Answers (1)

Rob
Rob

Reputation: 27367

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);

Upvotes: 2

Related Questions