当前,我正在尝试解析的API收到动态JSON响应。收到的JSON示例如下:
{
"data": [
{
"Id": "XXXXXXXXXXXXXXXXXXXXXXXX",
"IsActive": true,
"DateCreated": "2017-11-09T00:01:49.827Z",
"DateModified": "2017-11-09T00:01:49.827Z",
"IsDeleted": false,
"Uid": "XXXXXXXXXXXXXXXXXXXXXXXX",
"CustomObject": {
"customdata1": " Store my customdata1 value",
"customdata2": " Store my customdata2 value"
}
}
],
"Count": 1
}
在上述JSON中,在序列化时,我希望CustomObject映射到C#对象中的字符串。下面是我想要的对象结构的示例。
[System.Runtime.Serialization.DataContract]
public class CustomObjectData
{
[System.Runtime.Serialization.DataMember]
public string Id { get; set; }
[System.Runtime.Serialization.DataMember]
public bool IsActive { get; set; }
[System.Runtime.Serialization.DataMember]
public string DateCreated { get; set; }
[System.Runtime.Serialization.DataMember]
public string DateModified { get; set; }
[System.Runtime.Serialization.DataMember]
public bool IsDeleted { get; set; }
[System.Runtime.Serialization.DataMember]
public string Uid { get; set; }
[System.Runtime.Serialization.DataMember]
public string CustomObject { get; set; }
}
[System.Runtime.Serialization.DataContract]
public class CustomObjectDataHolder
{
[System.Runtime.Serialization.DataMember]
public List<CustomObjectData> data { get; set; }
[System.Runtime.Serialization.DataMember]
public int Count { get; set; }
}
我正尝试将其开发为CRM的插件,因此无法使用NewtonSoft等其他第三方JSON序列化器。