【问题标题】:Deserialize Facebook Workplace SCIM Rest API response反序列化 Facebook Workplace SCIM Rest API 响应
【发布时间】:2018-01-25 12:13:20
【问题描述】:

我正在尝试使用 C# NewtonSoft.Json 库反序列化以下对强类型对象的响应。 问题是如何反序列化最后一部分

"urn:scim:schemas:extension:enterprise:1.0": {"department": "Headquarters"} 变成一个对象。

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

我的强类型类是

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; }
    }

Address 节点的类

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

}

电子邮件节点的类

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; }
}

【问题讨论】:

  • 你能展示你的强类型类吗?
  • 请查看我审核过的答案

标签: c# json facebook api


【解决方案1】:

好吧,你应该只创建一个属性,并使用JsonProperty 属性:

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

但不确定 Enterprise 的名称。

documentation about that

【讨论】:

  • 简写是[JsonProperty("urn:scim:schemas:extension:enterprise:1.0")]
猜你喜欢
  • 2015-04-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多