1 返回json格式的数据
2:json 格式:[{1},{2}{3},{4},{5},{6}]
using System.Web.Script.Serialization; //命名空间
public partial class index : System.Web.UI.Page
{
BLL.events bll_event = new Maticsoft.BLL.events();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadEts();
}
}
protected void LoadEts()
{
string conditoin="";
string topnum = "";
if (Request.QueryString["title"] !=null)
{
conditoin = " where classname = '"+ Request.QueryString["title"].ToString().Trim()+"'";
}
if (Request.QueryString["count"] != null)
{
topnum = " top " + topnum;
}
JavaScriptSerializer json = new JavaScriptSerializer();
DataTable ds_event = bll_event.getEventBySomeWhere(topnum,conditoin);
if (ds_event.Rows.Count > 0)
{
string str = string.Empty;
for (int i = 0; i < ds_event.Rows.Count; i++)
{
DataRow dr=ds_event.Rows[i];
Model.events oneevent = new Maticsoft.Model.events();
oneevent.id =int.Parse(dr["id"].ToString());
oneevent.title = dr["title"].ToString();
oneevent.username=dr["username"].ToString();
oneevent.pic=dr["pic"].ToString();
oneevent.address = dr["address"].ToString();
oneevent.cityaddress = dr["cityaddress"].ToString();
oneevent.starttime =DateTime.Parse(dr["starttime"].ToString());
oneevent.endtime =DateTime.Parse(dr["endtime"].ToString());
oneevent.contents = dr["contents"].ToString();
oneevent.classname = dr["classname"].ToString();
oneevent.seecount =int.Parse(dr["seecount"].ToString());
oneevent.joincount =int.Parse(dr["joincount"].ToString());
oneevent.jionmoney = dr["jionmoney"].ToString();
oneevent.personcount =int.Parse(dr["personcount"].ToString());
oneevent.tudu = dr["tudu"].ToString();
oneevent.viewcount =int.Parse(dr["viewcount"].ToString());
str =str+"<br/>"+ json.Serialize(oneevent);//对象数据 变为json格式 数据
}
//this.Literal1.Text = str.ToString(); //赋值给控件显示
Response.Write(str.ToString()); // ios url请求是返回数据 的方式response.write()
Response.End();
}
}