省市县sql文件
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
StringBuilder strB = new StringBuilder();
strB.Append("{\"citylist\":");
DataTable dt = 省市县表;
List listC1 = new List();
foreach (DataRow item in dt.Rows)
{
if (item["parentid"].ToString() == "0")
{
Class1 c1 = new Class1();
c1.Id = item["id"].ToString();
c1.p = item["name"].ToString();
c1.c = new List();
foreach (DataRow item2 in dt.Rows)
{
if (item2["parentid"].ToString() == item["id"].ToString())
{
Class2 c2 = new Class2();
c2.Id = item2["id"].ToString();
c2.n = item2["name"].ToString();
c2.a = new List();
c1.c.Add(c2);
int index = 0;
foreach (DataRow item3 in dt.Rows)
{
if (item3["parentid"].ToString() == item2["id"].ToString())
{
Class3 c3 = new Class3();
c3.Id = item3["id"].ToString();
c3.s = item3["name"].ToString();
c2.a.Add(c3);
index += 1;
}
}
if (index == 0)
{
Class3 c3 = new Class3();
c3.Id = item2["id"].ToString();
c3.s = item2["name"].ToString();
c2.a.Add(c3);
}
}
}
listC1.Add(c1);
}
}
strB.Append(JsonConvert.SerializeObject(listC1).ToLower());
strB.Append("}");
Response.Write(strB.ToString());
}
}
public class Class1
{
string id;
public string Id
{
get { return id; }
set { id = value; }
}
string _p;
public string p
{
get { return _p; }
set { _p = value; }
}
List _c;
public List c
{
get { return _c; }
set { _c = value; }
}
}
public class Class2
{
string id;
public string Id
{
get { return id; }
set { id = value; }
}
string _n;
public string n
{
get { return _n; }
set { _n = value; }
}
List _a;
public List a
{
get { return _a; }
set { _a = value; }
}
}
public class Class3
{
string id;
public string Id
{
get { return id; }
set { id = value; }
}
string _s;
public string s
{
get { return _s; }
set { _s = value; }
}
}