zoukankan      html  css  js  c++  java
  • 数据库转换微信菜单

    1、根据添加到数据库的菜单转换json

    以最笨的方法写的,这个里面的可以进行简写

            public string GetListCategoryString()
            {
    
    
    
    
                string sql = "select * from T_WX_Category where sale_id=1 and p_id=0";
                DataTable dt = DbHelperSQL.Query(sql).Tables[0];
                string json = "{'button':[{'type': 'scancode_waitmsg', 'name': 'xss', 'key': 'qrcode'},";
    
    
    
                //主菜单
                foreach (DataRow row in dt.Rows)
                {
    
    
                    json += "{'name':'" + row["cate_name"] + "'";
    
                    //子菜单
                    string sqls = "select * from T_WX_Category where sale_id=1 and p_id=" + row["id"];
                    DataTable dts = DbHelperSQL.Query(sqls).Tables[0];
                    if (dts.Rows.Count > 0)
                    {
                        json += ",'sub_button':[";
                        foreach (DataRow rows in dts.Rows)
                        {
                            
                                if (dts.Rows.IndexOf(rows) == dts.Rows.Count - 1)
                                {
    
                                    //最后一行
                                    json += "{ 'type':'scancode_waitmsg','name': '" + rows["cate_name"] + "','key': 'qty'}]},";
                                   
                                }
                                else
                                {
                                    json += "{ 'type':'scancode_waitmsg','name': '" + rows["cate_name"] + "','key': 'qty'},";
                                }
                        }
                    }
                    else {
                        json += "}";
    
                    }
                   
    
    
    
    
    
                }
    
                json += ",{'type': 'view', 'name': '我', 'url': 'http://wm.risingtec.com.cn/OAuthRedirectUri.aspx?type=user'}]}";
    
                return json;
    
    
            }
    

      

  • 相关阅读:
    ACCP7.0-S2-复习自测-15测试分析
    线程
    多线程下的单例模式
    combobox 属性、事件、方法
    java的多线程总结
    爬虫--登录网页
    shell--字符串是否为空
    python--正则表达式 字符串匹配
    mysql---表所在数据库
    python--日期操作
  • 原文地址:https://www.cnblogs.com/mengluo/p/7784939.html
Copyright © 2011-2022 走看看