【发布时间】:2011-12-28 13:10:33
【问题描述】:
public class ApiResponse<T> : IApiResponse<T>
{
public long QuotaRemaining { get; set; }
public long QuotaMax { get; set; }
public int Backoff { get; set; }
public bool HasMore { get; set; }
public long Total { get; set; }
public string Type { get; set; }
//public long ErrorId { get; set; }
//public string ErrorMessage { get; set; }
//public string ErrorName { get; set; }
public IList<T> Items { get; set; }
public ApiError Error { get; set; }
}
public class ApiError
{
[JsonProperty("error_id")]
public long ErrorId { get; set; }
[JsonProperty("error_message")]
public string ErrorMessage { get; set; }
[JsonProperty("error_name")]
public string ErrorName { get; set; }
}
问题是Error 属性实际上与ApiResponse<T> 处于同一级别,但我想将它们包装到ApiError 类中,我该如何做到这一点?
我目前正在像这样反序列化:
public static T DeserializeJson<T>(this string json)
{
return JsonConvert.DeserializeObject<T>(json);
}
我想有一些属性可以让我很容易地完成这项工作,但我无法弄清楚该配置应该是什么。
【问题讨论】:
标签: c# json serialization