我正在尝试从活动目录格式化我的数据,以便我可以将其传递JavaScriptSerialzer
并以 JSON 格式输入。它还必须采用以下格式:
[{"id":"1","name":"Foo"},
{"id":"2","name":"Bar"}]
foreach (SearchResult sResultSet in search.FindAll())
{
if (sResultSet.Properties["displayName"].Count > 0)
{
nameList.Add(string.Format("({0}-{1})",sResultSet.Properties["displayName"][0], sResultSet.Properties["mail"][0]));
}
}
JavaScriptSerializer serializer = new JavaScriptSerializer();
string output = serializer.Serialize(nameList);
return nameList.ToArray();