弄一下午了,实在。。。。沮丧。
{ "menu": { "button": [ { "type": "click", "name": "今日歌曲", "key": "V1001_TODAY_MUSIC", "sub_button": [] }, { "type": "click", "name": "歌手简介", "key": "V1001_TODAY_SINGER", "sub_button": [] }, { "name": "菜单", "sub_button": [ { "type": "view", "name": "搜索", "url": "http://www.soso.com/", "sub_button": [] }, { "type": "view", "name": "视频", "url": "http://v.qq.com/", "sub_button": [] }, { "type": "click", "name": "赞一下我们", "key": "V1001_GOOD", "sub_button": [] } ] } ] } }
[DataContract] public class MenuButton { [DataMember(Name = "type")] public string type { get; set; } [DataMember(Name = "name")] public string name { get; set; } [DataMember(Name = "key")] public string key { get; set; } //不清楚到底是不是要这么写 //[DataMember(Name = "sub_button")] //public List<MenuButton> sub_button { get; set; } } [DataContract] public class Menus { [DataMember(Name = "menu")] public List<MenuButton> button { get; set; } }
var j = new JsonTextReader(new StringReader(jsontext)); var serializer = new JsonSerializer(); var menus = serializer.Deserialize<Menus>(j);
现在打算用Newtonsoft.Json 序列化成对象,但对JSON数据格式不是很熟悉,导致序列化不出来,应该是对象机构有问题,请指教下,谢谢!