• 根据城市表生成json数据


             T_CityManager am = new T_CityManager();
                    string tou = "var LAreaData=[";
                    string value = "";
                    List<T_City> plist = am.GetAllBySQL(" AND FParentID=0").ToList();
                    int count = 0;
                    foreach (T_City prov in plist)
                    {
                        if (count == 0)
                        {
                            value += "{"id":"" + prov.PID + "","name":"" + prov.FName + """;
    
                        }
                        else
                        {
                            value += ",{"id":"" + prov.PID + "","name":"" + prov.FName + """;
                        }
    
                        List<T_City> slist = am.GetAllBySQL(" AND FParentID=" + prov.PID).ToList();
                        if (slist.Count > 0)
                        {
                            value += ","child":[";
                        }
                        else if (slist.Count == 1)
                        {
                            value += "},";
                        }
    
    
                        foreach (T_City city in slist)
                        {
    
                            value += "{"id":"" + city.PID + "","name":"" + city.FName + """;
                            List<T_City> qlist = am.GetAllBySQL(" AND FParentID=" + city.PID).ToList();
                            if (qlist.Count==0)
                            {
                                value += "},";
                            }
                            if (qlist.Count > 0)
                            {
                                value += ","child":[";
                            }
    
                            foreach (var qu in qlist)
                            {
                                value += "{"id":"" + qu.PID + "","name":"" + qu.FName + ""},";
                            }
                            if (qlist.Count > 0)
                            {
                                value = value.Substring(0, value.Length - 1);
                                value += "]},";
                            }
                        }
                        if (slist.Count > 0)
                        {
                            value = value.Substring(0, value.Length - 1);
                            value += "]}";
                        }
    
                        count++;
                    }
                    tou = tou + value + "]";
                }
  • 相关阅读:
    aws centos 基本环境安装
    aws 安装python解释器
    odoo 开发环境部署
    graphql规范
    python 字符串format使用
    设计模式
    集合的常见操作
    字典常见操作
    python实现简单的购物车
    python实现简单的登录管理
  • 原文地址:https://www.cnblogs.com/linyijia/p/7662750.html
Copyright © 2020-2023  润新知