{"result":{"dataList":[{"name":"张三","sex":0,"time":{"date":15,"day":4,"hours":1},"status":0},{"name":"李四","sex":1,"time":{"date":12,"day":4,"hours":1},"status":1}]},"msg":"ok"}
上面是JSON格式,想用Newtonsoft.Json反序列化。
思路就是先定义.NET类,但是我不知道上面的类该如何定义,然后才能转换啊!
class timeItem{public int date; public int day ; public int hours ;}
class dataItem{ public string name; public int sex; public timeItem time;public int status;}
class resultItem{ public List<dataItem> dataList;}
class resultModel{ public resultItem result;public string msg;}
我也是改了下,和你这个格式是一样的就过了,还是谢谢你!
你把它按照树形格式显示下。
构造出层次结构:
public class Model { [JsonProperty("msg")] public string Msg{get;set;} } public class Result { [JsonProperty("dataList")] public IList<Data> DataList{get;set;} } public class Data { [JsonProperty("name")] public string Name{get;set;} [JsonProperty("sex")] public int Sex{get;set;} [JsonProperty("time")] public DataTime Time{get;set;} [JsonProperty("status")] public int Status{get;set;} } public class DataTime { [JsonProperty("date")] public int Date{get;set;} [JsonProperty("day")] public int Day{get;set;} [JsonProperty("hours")] public int Hours{get;set;} }