惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Attack and Defense Labs
Attack and Defense Labs
The GitHub Blog
The GitHub Blog
C
Check Point Blog
博客园_首页
MongoDB | Blog
MongoDB | Blog
N
Netflix TechBlog - Medium
F
Full Disclosure
Microsoft Security Blog
Microsoft Security Blog
爱范儿
爱范儿
Recent Announcements
Recent Announcements
阮一峰的网络日志
阮一峰的网络日志
G
GRAHAM CLULEY
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Threat Research - Cisco Blogs
C
Cybersecurity and Infrastructure Security Agency CISA
V
Vulnerabilities – Threatpost
K
Kaspersky official blog
博客园 - 司徒正美
S
Schneier on Security
T
The Exploit Database - CXSecurity.com
Project Zero
Project Zero
云风的 BLOG
云风的 BLOG
Cisco Talos Blog
Cisco Talos Blog
Know Your Adversary
Know Your Adversary
雷峰网
雷峰网
V
V2EX - 技术
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Spread Privacy
Spread Privacy
罗磊的独立博客
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
Security Affairs
SecWiki News
SecWiki News
Schneier on Security
Schneier on Security
O
OpenAI News
Jina AI
Jina AI
PCI Perspectives
PCI Perspectives
Cyberwarzone
Cyberwarzone
Y
Y Combinator Blog
Apple Machine Learning Research
Apple Machine Learning Research
B
Blog RSS Feed
I
InfoQ
D
Docker
P
Palo Alto Networks Blog
Recorded Future
Recorded Future
M
MIT News - Artificial intelligence
博客园 - Franky
B
Blog
Scott Helme
Scott Helme
博客园 - 叶小钗
D
DataBreaches.Net

博客园 - 你约我交友网

如何在mssql中获取最新自增ID的值 C#操作SQL Server通用类 如何在HTML5 图片预览 js本地图片预览代码兼容所有浏览器 c#无损高质量压缩图片 c#如何在win7下设置IE代理的完美解决方案 关于Android 访问权限设置 jquery 实现 点击按钮后倒计时效果,多用于实现发送手机验证码、邮箱验证码 在asp.net mvc中将checkbox传到后台时总是true的解决方法 Jquery实现文本框获取焦点清空内容,失去焦点重新获得内容的公共函数 - 你约我交友网 淘宝下单高并发解决方案 如何用jquery操作table的方法 免费交友网站关键词优化的几种好方法 关于c# asp.net中随机函数重复的解决方法 如何在linux云主机上添加网站 网站优化方面的资料 C# 启用或禁用网卡 2种方法 Jquery图片滚动 js幻灯片大全
asp.net 输出微信自定义菜单json
你约我交友网 · 2018-10-23 · via 博客园 - 你约我交友网

不多说了直接上代码

要引用 using LitJson;

// 根据Menu列表生成符合微信规范的创建菜单JSon
        //一级菜单不超过3个,二级菜单不超过5个
        //微信唯一标示
        //菜单列表,type为click时url留空,view时key留空
        public string CreateMenuJson()
        {
            DataTable table = new wxMenuModels().getTable();
            DataRow[] dt = table.Select("wx_parent=0");
            JsonData jd = new JsonData();
            jd["button"] = new JsonData();
            foreach(DataRow h in dt)
            {
                if(Convert.ToInt32(h["IsSub"])==1)//有子菜单
                {
                    JsonData json = new JsonData();
                    json["name"] = h["wx_name"].ToString();
                    json["sub_button"] = new JsonData();
                    DataRow[] dtt = table.Select("wx_parent="+h["wx_ID"].ToString());
                    foreach(DataRow hh in dtt)
                    {
                        JsonData tempJson = new JsonData();
                        tempJson["type"] = hh["wx_type"].ToString();
                        tempJson["name"] = hh["wx_name"].ToString();
                        if(!string.IsNullOrEmpty(hh["wx_key"].ToString()))
                        {
                            tempJson["key"] = hh["wx_key"].ToString();
                        }
                        else
                        {
                            tempJson["url"] = hh["wx_url"].ToString();
                        }
                        json["sub_button"].Add(tempJson);
                    }
                    jd["button"].Add(json);
                }
                else //无子菜单
                {
                    JsonData tempJson = new JsonData();
                    tempJson["type"] = h["wx_type"].ToString();
                    tempJson["name"] = h["wx_name"].ToString();
                    if (!string.IsNullOrEmpty(h["wx_key"].ToString()))
                    {
                        tempJson["key"] = h["wx_key"].ToString();
                    }
                    else
                    {
                        tempJson["url"] = h["wx_url"].ToString();
                    }
                    jd["button"].Add(tempJson);
                }
            }
            return jd.ToJson();
        }

posted @ 2018-10-23 11:45  你约我交友网  阅读(296)  评论()    收藏  举报