/// <summary> /// 获取API接口数据 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="apistr"></param> /// <param name="resulturl"></param> /// <returns></returns> public static T Data <T>(this string target, string param, string method = "POST") { T list = default(T); try { string resu = RequestApi(target, param, method); if (!string.IsNullOrEmpty(resu)) { JsonCommModel <T> seclist = JsonHelper.JSONToObject <JsonCommModel <T> >(resu); if (null != seclist && seclist.BackStatus == 0) { list = seclist.Data; } else { log.Error("读取接口错误,错误信息:" + seclist.Msg); } } } catch (Exception e) { log.Error("读取接口错误,错误信息:", e); } return(list); }
public static string DataList <T>(List <T> t) { string returnstr = ""; JsonCommModel <List <T> > jsoncList = new JsonCommModel <List <T> >(); if (t != null && t.Count > 0) { jsoncList.BackStatus = 0; jsoncList.Msg = "success"; jsoncList.Data = t; } else { jsoncList.BackStatus = 1; jsoncList.Msg = "fail,数据异常"; } returnstr = JsonHelper.ObjectToJSON(jsoncList); return(returnstr); }
public static string DataPageList <T>(PagedList <T> list, int totalCount, int pageIndex) { string returnstr = ""; JsonCommModel <PagedList <T> > jsoncList = new JsonCommModel <PagedList <T> >(); if (list != null && list.Count > 0) { jsoncList.BackStatus = 0; jsoncList.Msg = "success"; jsoncList.Data = list; jsoncList.TotalCount = totalCount; jsoncList.PageIndex = pageIndex; } else { jsoncList.BackStatus = 1; jsoncList.Msg = "fail,数据异常"; } returnstr = JsonHelper.ObjectToJSON(jsoncList); return(returnstr); }