【学艺不精系列】关于Json.NET的反序列化
using Newtonsoft.Json.Converters; [JsonObject] public class Schedule { public string Status { get; set; } public string Message { get; set; } [JsonProperty("Data")] public List<Task> Tasks { get; set; } } [JsonObject] public class Task{ public string Id { get; set; } public string Ops { get; set; } } string jsonData = "{Status:1, Message:\"message\", Data:{[Id:1,Ops:\"\"],[Id:2,Ops:\"\"],[Id:3,Ops:\"\"]}}" Schedule schedule = JsonConvert.DeserializeObject<Schedule>(jsonData);
之前反序列化生成的schedule的Tasks属性总是null,左思右想,是不是缺少include type之类的;最后搞定才发现Json给的属性名是Data,杯具啊……