把一个集合自定转成json字符串

List<CityData> listData =new List<CityData>();
//把一个集合自定转成json字符串。
foreach (var city in ctiyTable)
{
listData.Add(new CityData()
{
CityId = city.CityID,
CityName = city.CityName
});
}

System.Web.Script.Serialization.JavaScriptSerializer javaScriptSerializer =new JavaScriptSerializer();
var response= javaScriptSerializer.Serialize(listData);

posted @ 2019-04-28 15:36  咖啡无眠  阅读(911)  评论(0编辑  收藏  举报