Esempio n. 1
0
        /// <summary>
        /// HttpResponse
        /// </summary>
        /// <param name="httpResponseMessage"></param>
        /// <param name="settings">JsonSerializerSettings</param>
        public HttpResponse(HttpResponseMessage httpResponseMessage, JsonSerializerSettings settings = null)
        {
            StatusCode = (int)httpResponseMessage.StatusCode;
            Headers    = httpResponseMessage.Headers;
            string bodyStr = httpResponseMessage.Content.ReadAsStringAsync().Result;

            if (!string.IsNullOrWhiteSpace(bodyStr))
            {
                Body = SnowLeopardJsonConvert.DeserializeObject <T>(bodyStr, settings);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Json反序列化
 /// </summary>
 /// <typeparam name="T">返回类型</typeparam>
 /// <param name="input">Json字符串</param>
 /// <param name="settings">The JsonSerializer Settings</param>
 /// <returns>强类型</returns>
 public static T JsonDeserialize <T>(string input, JsonSerializerSettings settings = null)
 {
     try
     {
         T rv = SnowLeopardJsonConvert.DeserializeObject <T>(input, settings);
         return(rv);
     }
     catch
     {
         return(default(T));
     }
 }