LDAP 搜索对 Json C# 的响应



我正在使用C# LdapConnection来获取工作中的SearchResponse。 我可以将 SearchResponse 放入 Json 字符串中,但无法将该 Json 字符串放入具有模仿 SearchResponse 的属性的对象类中。 JSON 字符串的格式正确。 我是否以错误的方式使用了Newtonsoft.Json库? 有没有更好的方法可以做到这一点? 我唯一的要求是将 SearchResponse 放入我的对象类 (DirectoryEntity( 中,以便我可以从那里使用它。

我的控制台应用程序:

class Program
{
static void Main(string[] args)
{
LdapClient client = new LdapClient();
List<LdapSearchResponseModel> list = new List<LdapSearchResponseModel>();
string query = "(|(uupid=name1)(uupid=name2))";
string[] attributes = new string[] { };
string host = "id.directory.univ";
int port = 1234;
SearchResponse response = client.RawQuery(query, attributes, host, port);
string json = JsonConvert.SerializeObject(response);
var test = JsonConvert.DeserializeObject<DirectoryEntities>(json);
}
}

我的目录实体类:

public class DirectoryEntity
{
public string EntityDN { get; set; }
public int MailStop { get; set; }
public List<string> UniversityAffiliation { get; set; }
public int UniversityId { get; set; }
public string GivenName { get; set; }
public string Title { get; set; }
public string PasswordState { get; set; }
public string MiddleName { get; set; }
public string AccountState { get; set; }
public int Uid { get; set; }
public string Mail { get; set; }
public string MailPreferredAddress { get; set; }
public DateTime DateOfBirth { get; set; }
public List<string> GroupMembership { get; set; }
public string DegreeType { get; set; }
public int ClassLevelCode { get; set; }
public string AuthId { get; set; }
public string Major { get; set; }
public string ClassLevel { get; set; }
public bool SupressDisplay { get; set; }
public string UnderGraduateLevel { get; set; }
public string ObjectClass { get; set; }
public int DepartmentNumber { get; set; }
public List<string> EduPersonAffiliation { get; set; }
public string LocalPostalAddress { get; set; }
public string Uupid { get; set; }
public string LocalPhone { get; set; }
public string TelephoneNumber { get; set; }
public string Department { get; set; }
public string Sn { get; set; }
}

我的目录实体类:

public class DirectoryEntities
{
public List<DirectoryEntity> Entities { get; set; }
public int Count { get; set; }
}

您是否尝试过为 DirectoryEntity 类显式定义默认构造函数?我相信Newtonsoft要求对象在反序列化之前具有默认构造函数。尝试将其添加到 DirectoryEntity 类中:

public DirectoryEntity() { }

最新更新