1.添加引用 using System.Web.Services;

2.添加方法

[WebMethod]
public static string getFoodClasses(int parentID)
{
onnEntities onndb = new onnEntities();  //定义数据连接对象
string strJson = “{\”classlist\”:[“;
IQueryable<food_class> fcList = onndb.food_class.Where(s => s.class_ParentClassID == parentID);
foreach (food_class i in fcList)
{
strJson += “{\”id\”: ” + i.class_ID + “,\”title\”:\” ” + i.class_Title + “\”},”;
}
strJson = strJson.Substring(0, strJson.Length – 1);
strJson += “]}”;
return strJson;
}

版权声明:本文为gurder原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/gurder/p/9658236.html