if (ds.Tables[0].Rows.Count != 0) { var list = GetJsonString(ds.Tables[0]); jsonStr = "{'jsonStr':'" + list + "','result':'1'}"; }
public string GetJsonString(DataTable DS) { List<Voucher> list = new List<Voucher>(); for (int i = 0; i < DS.Rows.Count; i++) { Voucher cd=new Voucher(); cd.id=DS.Rows[i]["VID"].ToString(); list.Add(cd); } VoucherList voucherlist = new VoucherList(); voucherlist.GetVoucher = list; return new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(voucherlist); } public class Voucher { public string id{ get; set; } } public class VoucherList { public System.Collections.Generic.List<Voucher> GetVoucher { get; set; } }