gpt4 book ai didi

c# - Azure Active Directory 用户(类型=具有现有用户帐户的用户)Json 列表模型给出 null

转载 作者:行者123 更新时间:2023-12-03 04:34:15 24 4
gpt4 key购买 nike

我想将 Json 结果反序列化为模型。我正在使用 Azure 单点登录方法。当我使用广告中新创建的用户(您组织中的新用户)登录时,我得到了正确的用户信息。但是如果我使用“具有现有用户帐户的用户”在 AzureAd 中创建新用户。我可以登录并且请求也经过身份验证。但我没有得到用户个人资料。用户个人资料为空。但“responseString”包含用户的所有值。任何人都可以帮助我吗?

UserProfile profile = JsonConvert.DeserializeObject<UserProfile>(responseString);

public class UserProfile
{
public string DisplayName { get; set; }
public string GivenName { get; set; }
public string Surname { get; set; }
}

Json

拥有现有用户帐户的用户

{"odata.metadata":"https://graph.windows.net/780cdd84-48ba-4be3-8d66-b40b8bee6b0b/$metadata#directoryObjects/Microsoft.WindowsAzure.ActiveDirectory.User","value":[{"odata.type":"Microsoft.WindowsAzure.ActiveDirectory.User","objectType":"User","objectId":"****************","accountEnabled":true,"assignedLicenses":[],"assignedPlans":[],"city":null,"country":null,"department":null,"dirSyncEnabled":null,"displayName":"mahesh","facsimileTelephoneNumber":null,"givenName":"map","jobTitle":null,"lastDirSyncTime":null,"mail":null,"mailNickname":"devb_azureteam.com#EXT#","mobile":null,"otherMails":["<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8befeefde9cbeaf1fef9eeffeeeae6a5e8e4e6" rel="noreferrer noopener nofollow">[email protected]</a>"],"passwordPolicies":"None","passwordProfile":null,"physicalDeliveryOfficeName":null,"postalCode":null,"preferredLanguage":null,"provisionedPlans":[],"provisioningErrors":[],"proxyAddresses":[],"state":null,"streetAddress":null,"surname":"map","telephoneNumber":null,"usageLocation":null,"userPrincipalName":"devb_azureteam.com#EXT#@AzureteamLoginTest.onmicrosoft.com"},

{"odata.type":"Microsoft.WindowsAzure.ActiveDirectory.User","objectType":"User","objectId":"****************","accountEnabled":true,"assignedLicenses":[],"assignedPlans":[],"city":null,"country":null,"department":null,"dirSyncEnabled":null,"displayName":"Education at AzureTeam","facsimileTelephoneNumber":null,"givenName":"Education","jobTitle":null,"lastDirSyncTime":null,"mail":null,"mailNickname":"education_azureteam.com#EXT#","mobile":null,"otherMails":["<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f99c9d8c9a988d909697b998838c8b9c8d9c9894d79a9694" rel="noreferrer noopener nofollow">[email protected]</a>"],"passwordPolicies":null,"passwordProfile":null,"physicalDeliveryOfficeName":null,"postalCode":null,"preferredLanguage":null,"provisionedPlans":[],"provisioningErrors":[],"proxyAddresses":[],"state":null,"streetAddress":null,"surname":"at AzureTeam","telephoneNumber":null,"usageLocation":null,"userPrincipalName":"education_azureteam.com#EXT#@AzureteamLoginTest.onmicrosoft.com"},
{"odata.type":"Microsoft.WindowsAzure.ActiveDirectory.User","objectType":"User","objectId":"*****************","accountEnabled":true,"assignedLicenses":[],"assignedPlans":[],"city":null,"country":null,"department":null,"dirSyncEnabled":null,"displayName":"mahesh","facsimileTelephoneNumber":null,"givenName":"mahesh","jobTitle":null,"lastDirSyncTime":null,"mail":null,"mailNickname":"mahesh","mobile":null,"otherMails":["<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a5c8c4d5e5c4dfd0d7c0d1c0c4c88bc6cac8" rel="noreferrer noopener nofollow">[email protected]</a>"],"passwordPolicies":"None","passwordProfile":null,"physicalDeliveryOfficeName":null,"postalCode":null,"preferredLanguage":null,"provisionedPlans":[],"provisioningErrors":[],"proxyAddresses":[],"state":null,"streetAddress":null,"surname":null,"telephoneNumber":null,"usageLocation":null,"userPrincipalName":"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2d404c45485e456d6c57585f4859484c4061424a444379485e5903424340444e5f425e424b59034e4240" rel="noreferrer noopener nofollow">[email protected]</a>"}]}

New user in organization

{"odata.metadata":"https://graph.windows.net/780cdd84-48ba-4be3-8d66-b40b8bee6b0b/$metadata#directoryObjects/Microsoft.WindowsAzure.ActiveDirectory.User/@Element","odata.type":"Microsoft.WindowsAzure.ActiveDirectory.User","objectType":"User","objectId":"************","accountEnabled":true,"assignedLicenses":[],"assignedPlans":[],"city":null,"country":null,"department":null,"dirSyncEnabled":null,"displayName":"mahesh","facsimileTelephoneNumber":null,"givenName":"mahesh","jobTitle":null,"lastDirSyncTime":null,"mail":null,"mailNickname":"mahesh","mobile":null,"otherMails":["<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="89e4e8f9c9e8f3fcfbecfdece8e4a7eae6e4" rel="noreferrer noopener nofollow">[email protected]</a>"],"passwordPolicies":"None","passwordProfile":null,"physicalDeliveryOfficeName":null,"postalCode":null,"preferredLanguage":null,"provisionedPlans":[],"provisioningErrors":[],"proxyAddresses":[],"state":null,"streetAddress":null,"surname":null,"telephoneNumber":null,"usageLocation":null,"userPrincipalName":"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e18c8089849289a1a09b9493849584808cad8e86888fb5849295cf8e8f8c8882938e928e8795cf828e8c" rel="noreferrer noopener nofollow">[email protected]</a>"}

最佳答案

你实际上得到了不同的 JSON。我简化了它们以显示问题。对于新用户 JSON 看起来像这样:

{  
"odata.metadata":"...Microsoft.WindowsAzure.ActiveDirectory.User/@Element",
"odata.type":"Microsoft.WindowsAzure.ActiveDirectory.User",
"displayName":"mahesh",
"givenName":"mahesh",
"surname":null
}

反序列化将适用于您的模型。但对于现有用户 JSON 是:

{  
"odata.metadata":"...Microsoft.WindowsAzure.ActiveDirectory.User",
"value":[
{
"odata.type":"Microsoft.WindowsAzure.ActiveDirectory.User",
"displayName":"mahesh",
"givenName":"map",
"surname":"map"
},
{ },
{ }
]
}

如您所见,您有一个包含用户数组的 value 属性。因此,为了能够反序列化它,您需要创建新模型:

public class RootObject
{
public List<UserProfile> Value { get; set; }
}

然后:

var obj = JsonConvert.DeserializeObject<RootObject>(json);

我与 Azure Active Directory 不相似,但您应该检查为什么这些响应的 odata.metadata 属性不同。

关于c# - Azure Active Directory 用户(类型=具有现有用户帐户的用户)Json 列表模型给出 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29915924/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com