2017-08-17 19 views
0

我想反序列化使用C#NewtonSoft.Json庫的強類型對象的下面的響應。 問題是如何反序列化最後一部分反序列化Facebook工作場所SCIM Rest API響應

"urn:scim:schemas:extension:enterprise:1.0": {"department": "Headquarters"} 進入一個對象。

{ 
    "schemas": [ 
    "urn:scim:schemas:core:1.0", 
    "urn:scim:schemas:extension:enterprise:1.0" 
    ], 
    "userName": "[email protected]", 
    "name": { 
    "formatted": "Ihab Mahmoud" 
    }, 
    "active": true, 
    "emails": [ 
    { 
     "primary": true, 
     "type": "work", 
     "value": "[email protected]" 
    } 
    ], 
    "addresses": [ 
    { 
     "type": "work", 
     "formatted": "QOC Headquarter", 
     "primary": true 
    } 
    ], 
    "urn:scim:schemas:extension:enterprise:1.0": { 
    "department": "Headquarters" 
    } 
} 

我Strongle類型類是

public class WPClass 
    { 
     public List<string> Schemas { get; set; } 
     public string Username { get; set; } 
     public NameNode Name { get; set; } 
     public bool Active { get; set; } 
     public List<EmailNode> Emails { get; set; } 
     public List<AddressNode> Addresses { get; set; } 
    } 

爲地址節點

public class AddressNode 
{ 
    public string Type { get; set; } 
    public string formatted { get; set; } 
    public bool Primary { get; set; } 

} 

類的電子郵件節點的類

雖然

[JsonProperty(PropertyName = "urn:scim:schemas:extension:enterprise:1.0")] 
public YourEnterpriseType Enterprise { get; set; } 

不知道在Enterprise名稱:0

public class EmailNode 
{ 
    public bool Primary { get; set; } 
    public string Type { get; set; } 
    public string Value { get; set; } 

} 

類的名稱節點

public class NameNode 
{ 
    public string formatted { get; set; } 
} 
+0

你能展示你的強類型類嗎? – ZwoRmi

+0

請檢查我的評論回答 –

回答

1

那麼,你應該只創建一個屬性,並使用JsonProperty屬性。

documentation about that

+1

簡寫爲'[JsonProperty(「urn:scim:schemas:extension:enterprise:1.0」)]' – ZwoRmi

+0

非常感謝。這解決了我的問題。欣賞它。 –