Example #1
0
        /// <summary>
        /// 解析菜单
        /// </summary>
        /// <param name="jo"></param>
        /// <returns></returns>
        private static BaseMenu Parse(JObject jo)
        {
            JToken jt;

            if (jo.TryGetValue("type", out jt) && jo.TryGetValue("name", out jt))
            {
                MenuTypeEnum type = (MenuTypeEnum)Enum.Parse(typeof(MenuTypeEnum), (string)jo["type"]);
                string       name = (string)jo["name"];
                if (jo.TryGetValue("key", out jt) || jo.TryGetValue("url", out jt) || jo.TryGetValue("value", out jt))
                {
                    string info = (string)jt;
                    return(CreateItemByProgram(type, name, info));
                }
                else
                {
                    JArray        ja        = (JArray)jo["news_info"]["list"];
                    NewsForMenu[] news_info = new NewsForMenu[ja.Count];
                    for (int i = 0; i < ja.Count; i++)
                    {
                        news_info[i] = NewsForMenu.Parse((JObject)ja[i]);
                    }
                    return(new NewsMenu(name, news_info));
                }
            }
            else
            {
                string        name = (string)jo["name"];
                MenuContainer mc   = CreateContainer(name);
                JArray        ja   = null;
                if (jo.TryGetValue("sub_button", out jt))
                {
                    if (jt.Type == JTokenType.Array)
                    {
                        ja = (JArray)jt;
                    }
                    else if (jt.Type == JTokenType.Object && ((JObject)jt).TryGetValue("list", out jt))
                    {
                        if (jt.Type == JTokenType.Array)
                        {
                            ja = (JArray)jt;
                        }
                    }
                }
                if (ja != null)
                {
                    foreach (JObject item in ja)
                    {
                        mc.Add(Parse(item));
                    }
                }
                return(mc);
            }
        }
Example #2
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="type">类型</param>
 /// <param name="name">名称</param>
 /// <param name="news_info">图文消息</param>
 internal NewsMenu(string name, NewsForMenu news)
     : this(name, new NewsForMenu[] { news })
 {
 }