zoukankan      html  css  js  c++  java
  • 后台生成json数据

     /// <summary>
            /// 生成JS按钮事件
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            protected void LBCreateAdFile_Click(object sender, EventArgs e)
            {
                string sMapPath = Server.MapPath("/Js/Date/HomeAd.js");
                string sTxt = string.Empty;
    
                string sql = " where State = 1 order by HomeAdvertisingId desc";
                IList<HomeAdvertisingInfo> hailists = HomeAdvertisingBLL.GetHomeAdvertisingByStr(sql);
                if (hailists.Count > 0)
                {
                    sTxt = "var HomeAdObj = [";
                    for (int i = 0; i < hailists.Count; i++)
                    {
                        sTxt += "{"Label":" + """ + hailists[i].Label + """ + ","ImgUrl":" + """ + hailists[i].ImgUrl + """ + ","BackgroundColor":" + """ + hailists[i].BackgroundColor + """ + ","Link":" + """ + hailists[i].Link + """ + ","State":" + """ + hailists[i].State + """ + ","Sort":" + """ + hailists[i].Sort + """ + "}";
                        if (hailists.Count > 1 && i < hailists.Count - 1)
                        {
                            sTxt += ",";
                        }
                    }
                    sTxt += "];";
                    File.WriteAllText(sMapPath, sTxt);
                    MessageBox.Show(this.Page, "生成文件成功");
                }
                else
                {
                    MessageBox.Show(this.Page, "暂无数据");
                }
                BindData();
            }
    

      

  • 相关阅读:
    高进度乘法FFT优化
    Activity的四种加载模式
    异步任务AsyncTask
    利用Handler在子线程中更新UI
    Android 屏幕旋转监听
    HDOJ-1698-线段树成段更新
    HDOJ-1671-字典树
    HDOJ-1251 字典树
    python数据结构与算法
    find the lowest number location
  • 原文地址:https://www.cnblogs.com/nik2011/p/3225726.html
Copyright © 2011-2022 走看看