public void getJsonData()
{
StringBuilder sb = new StringBuilder();
string res = "";
try
{
List<calss1> list = calss1DAL.m_calss1Dal.GetList("id > 0", 1000, 1, false, "*", "id"); //表一
if (list.Count != 0)
{
res = "[";
for (int i = 0; i < list.Count; i++)
{
try
{
List<class2> list2 = class2DAL.m_class2Dal.GetList("字段= " + list[i].id.ToString(), 1000, 1, false, "*", "id"); //表二
if (list2.Count != 0)
{
res = res + "{";
res = res + "\"id\" : \"" + list[i].id.ToString() + "\",";
res = res + "\"value\" : \"" + list[i].name.ToString() + "\",";
res = res + "\"childs\" : [";
for (int j = 0; j < list2.Count; j++)
{
res = res + "{";
res = res + "\"id\" : \"" + list2[j].id.ToString() + "\",";
res = res + "\"value\" : \"" + list2[j].name.ToString() + "\"";
res = res + "},";
}
res = res.Substring(0, res.Length - 1);
res = res + "]},";
}
}
catch
{
;
}
}
res = res.Substring(0, res.Length - 1);
res = res + "]";
}
}
catch
{
;
}
sb.Append(res);
context.Response.Write(sb);
}
两张表拼凑json数据格式
最新推荐文章于 2022-04-02 11:41:03 发布