我正在尝试使用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; }
}
地址节点的类
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; }
}
答案 0 :(得分:1)
嗯,您应该只创建一个属性,并使用JsonProperty
属性:
[JsonProperty(PropertyName = "urn:scim:schemas:extension:enterprise:1.0")]
public YourEnterpriseType Enterprise { get; set; }
虽然不确定Enterprise
名称。