BAH.BOS.WebAPI.Client.APIException.CutJSONHeader C# (CSharp) Method

CutJSONHeader() public static method

将传入的序列化字符串去除头部定义。
public static CutJSONHeader ( string json ) : string
json string 序列化字符串。
return string
        public static string CutJSONHeader(string json)
        {
            if (!CheckStringIsAPIException(json))
            {
                return string.Empty;
            }//end if

            return json.Substring(JSONHeader.Length, json.Length - JSONHeader.Length);
        }//end method

Usage Example

Beispiel #1
0
        /// <summary>
        /// 以同步的形式发起HTTP请求并返回类型为泛型的API响应对象。
        /// </summary>
        /// <typeparam name="T">定义结果的泛型。</typeparam>
        /// <returns>返回结果类型为泛型的API响应对象。</returns>
        public virtual APIResponse <T> ToAPIResponse <T>()
        {
            var result = new APIResponse <T>();

            try
            {
                var response = Post().asString();
                result.StatusCode = (HttpStatusCode)response.Code;
                var json = response.Body;

                //判断返回的是否是一个异常数据包
                //如果是的,反序列化之,并引发一个异常
                //反之正常反序列化
                if (APIException.CheckStringIsAPIException(json))
                {
                    result.APIError = JsonConvert.DeserializeObject <APIException>(APIException.CutJSONHeader(json));
                    throw result.APIError.ToException();//这里会引发异常
                }//end if

                if (typeof(T).Equals(typeof(string)))
                {
                    result.Body = (T)(object)json;
                }
                else
                {
                    result.Body = JsonConvert.DeserializeObject <T>(json);
                }
            }
            catch (Exception ex)
            {
                result.Error = ex;
            }

            return(result);
        }//end method
All Usage Examples Of BAH.BOS.WebAPI.Client.APIException::CutJSONHeader