public static bool GetApiData(ApiBody body, ref int totalCount, ref string msg) { string returns = string.Empty; //参数 if (body.SendObj != null) { body.Params = GetParameters(body.SendObj); } if (body.SendType == SendType.Get) { returns = ApiByGet(body.ApiUrl, body.Params); } else if (body.SendType == SendType.Post) { //var paramsa = NewGetPrarams(body.SendObj); returns = ApiByPost(body.ApiUrl, body.Params); } var result = false; if (!string.IsNullOrEmpty(returns)) { var s = Newtonsoft.Json.JsonConvert.DeserializeObject(returns); var obj = JObject.Parse(s.ToString()); result = Convert.ToBoolean(obj["IsSuccessful"]); if (result && obj["Data"].ToString() != "[]") { totalCount = obj["TotalCount"] == null ? 0 : Convert.ToInt32(obj["TotalCount"]); } msg = obj["ErrorMessage"].ToString(); } return(result); }
public static T GetApiData <T>(ApiBody body, ref int totalCount) { string returns = string.Empty; //参数 if (body.SendObj != null) { body.Params = GetParameters(body.SendObj); } if (body.SendType == SendType.Get) { returns = ApiByGet(body.ApiUrl, body.Params); Tools.MessBox("GetApiData:" + returns); } else if (body.SendType == SendType.Post) { returns = ApiByPost(body.ApiUrl, body.Params); } if (!string.IsNullOrEmpty(returns)) { try { var t = JsonConvert.DeserializeObject <T>(returns); return(t); } catch (Exception ex) { Tools.MessBox("GetApiData:" + ex.ToString()); return(default(T)); } } return(default(T)); }