我从linq执行一个查询,它给出了一个列列表 这是查询:
function find_value_in_obj(arr_obj,value){
return !arr_obj.some(itm => itm == value);
}
以下是查询中的JSON数据
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);
我正在尝试将此数据反序列化为具有以下类
的C#类对象[{"UserFirstName":"Manager3","UserLastName":"ManagerLastName","UserEmailAddress":"manager3@test.com"}]
这是反序列化代码
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; }
}
答案 0 :(得分:2)
摆脱包装。您获得了一个数组,而不是包含数组作为属性的对象。
var jsonToDataTable = JsonConvert.DeserializeObject<List<UserGridDetails>>(value);