我正在反序列化 yahoo Contacts api 的 json 响应,一切进展顺利,但我在一个字段中遇到问题fields
,它是一个数组,但在所有元素中value
都不同,如何处理它。在两个字段中,这是字符串,在其他元素对象中。这是我的示例 json
"fields": [
{
"created": "2008-12-29T13:47:21Z",
"updated": "2008-12-29T13:47:21Z",
"uri": "http://social.yahooapis.com/v1/user/ASASASASASASA/contact/8/email/18",
"id": "18",
"type": "email",
"value": "papi@ymail.com",
"editedBy": "OWNER"
},
{
"created": "2010-03-30T07:02:04Z",
"updated": "2011-06-25T05:01:51Z",
"uri": "http://social.yahooapis.com/v1/user/ASASASASASASA/contact/8/guid/42",
"id": "42",
"type": "guid",
"value": "BMM5JTQVDB7G4EBPO2D5ESE3TI",
"editedBy": "OWNER",
"isConnection": "false"
},
{
"created": "2008-12-29T13:47:21Z",
"updated": "2008-12-29T13:47:21Z",
"uri": "http://social.yahooapis.com/v1/user/ASASASASASASA/contact/8/name/17",
"id": "17",
"type": "name",
"value": {
"givenName": "Hitesh",
"middleName": null,
"familyName": "Lohar",
"prefix": null,
"suffix": null,
"givenNameSound": null,
"familyNameSound": null
},
"editedBy": "OWNER"
}
]
我为 Field 创建了以下课程
public class YahooField
{
[JsonProperty("created")]
public string Created { get; set; }
[JsonProperty("updated")]
public string Updated { get; set; }
[JsonProperty("uri")]
public string Uri { get; set; }
[JsonProperty("id")]
public string Id { get; set; }
[JsonProperty("type")]
public string Type { get; set; }
//here confusion
//[JsonProperty("value")]
//public (String or class) Value { get; set; }
[JsonProperty("editedBy")]
public string EditedBy { get; set; }
[JsonProperty("isConnection")]
public string IsConnection { get; set; }
}