首页 新闻 会员 周边 捐助

c# Newtonsoft.Json JSON序列化

0
悬赏园豆:10 [已关闭问题] 解决于 2013-10-31 16:41

弄一下午了,实在。。。。沮丧。

{
    "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数据格式不是很熟悉,导致序列化不出来,应该是对象机构有问题,请指教下,谢谢!

醉低调的主页 醉低调 | 初学一级 | 园豆:128
提问于:2013-10-31 16:13
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册