創建一個用戶類,如下
public class ActiveDirectoryUser
{
public bool accountEnabled { get; set; }
public List<SignInName> signInNames { get; set; }
public string creationType { get; set; }
public string displayName { get; set; }
public string mailNickname { get; set; }
[JsonProperty("passwordProfile", NullValueHandling = NullValueHandling.Ignore)]
public PasswordProfile PasswordProfile { get; set; }
[JsonProperty("passwordPolicies", NullValueHandling = NullValueHandling.Ignore)]
public string PasswordPolicies { get; set; }
public string city { get; set; }
public object country { get; set; }
public object facsimileTelephoneNumber { get; set; }
public string givenName { get; set; }
public object mail { get; set; }
public object mobile { get; set; }
//public List<object> otherMails { get; set; }
public string postalCode { get; set; }
public object preferredLanguage { get; set; }
public string state { get; set; }
public object streetAddress { get; set; }
public string surname { get; set; }
public Guid objectId { get; set; }
public object telephoneNumber { get; set; }
}
public class SignInName
{
public string type { get; set; }
public string value { get; set; }
}
public class PasswordProfile
{
public string password { get; set; }
public bool forceChangePasswordNextLogin { get; set; }
}
當正從AD的反應,使用newtonsoft.json序列化到如下面相應的類。
var response = await httpClient.SendAsync(request);
if (response.IsSuccessStatusCode)
{
var result = response.Content.ReadAsStringAsync().Result;
return JsonConvert.DeserializeObject<ActiveDirectoryUser>(result);
}
訣竅是JsonConvert.DeserializeObject <>(結果);
是否有可能舉例說明您收到的JSON以及您希望獲得的結構?我認爲一個可靠的例子將有助於澄清你在找什麼。 :) –