public class Shop
{
public string Name { get; set; }
public string ShopID { get; set; }
}
protected void Page_Load(object sender, EventArgs e)
{
List<Shop> lst = new List<Shop>() {
new Shop(){Name="北京",ShopID="33"},
new Shop(){Name="上海",ShopID="823"}
};
WriteString(lst);
}
public static void WriteString(List<Shop_Item> lst_shop)
{
StringBuilder Json = new StringBuilder();
Json.Append("[");
if (lst_shop.Count > 0)
{
for (int i = 0; i < lst_shop.Count; i++)
{
Json.Append("{");
Json.AppendFormat("\"Name\":\"{0}\",", lst_shop[i].Name);
Json.AppendFormat("\"ShopID\":\"{0}\"", lst_shop[i].ShopID);
Json.Append("}");
if (i < lst_shop.Count - 1)
{
Json.Append(",");
}
}
}
Json.Append("]");
HttpContext.Current.Response.ContentType = "text/plain";
HttpContext.Current.Response.Write(Json.ToString());
//HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End(); ;
}