从DataTable获取Json数据

public string GetJson(DataTable dt){

  JavaScriptSerializer jss=new JavaScriptSerializer();

  jss.MaxJsonLength=Int32.MaxValue;

  System.Collections.Arraylist dic=new System.Collections.ArrayList();

  foreach(DataRow dr  in dt.Rows){

    System.Collections.Generic.Dictionary<string,string> drow=new System.Collections.Generic.Dictionary<string,string>();

    foreach(DataColumn dc in dt.Columns){

      drow.Add(dc.ColumnName,dr[dc.ColumnName]);

    }

  dic.Add(drow);

 

  }

  return jss.Serialize(dic);

}

posted @ 2016-08-17 16:36  sujingnuli  阅读(842)  评论(0编辑  收藏  举报