Пример #1
0
        /// <summary>
        /// 发起Post请求
        /// </summary>
        /// <typeparam name="TResult">响应结果类型</typeparam>
        /// <param name="requestUrl">请求地址</param>
        /// <param name="data">发送的字典数据</param>
        /// <returns>响应结果</returns>
        public TResult Post <TResult>(string requestUrl, Dictionary <string, string> data)
        {
            HttpContent content = null;

            if (data == null)
            {
                data = new Dictionary <string, string>();
            }
            content = new FormUrlEncodedContent(data);

            HttpResponseMessage response = null;

            response = client.PostAsync(requestUrl, content).Result;
            if (response.IsSuccessStatusCode)
            {
                var     str    = response.Content.ReadAsStringAsync().Result;
                TResult result = jsonProvider.DeserializeObject <TResult>(str);
                return(result);
            }
            else
            {
                var strException = Encoding.UTF8.GetString(response.Content.ReadAsByteArrayAsync().Result);
                throw new Exception(strException);
            }
        }
Пример #2
0
        public List <Player> GetPlayers()
        {
            var json    = _fileProvider.ReadAllText(GetConnectionString());
            var players = _jsonProvider.DeserializeObject(json);

            return(players);
        }
 public override T GetDataCore <T>(string key)
 {
     try
     {
         string jsonStr = GetString(key);
         return(string.IsNullOrWhiteSpace(jsonStr) ? default(T) : _jsonProvider.DeserializeObject <T>(jsonStr));
     }
     catch (Exception)
     {
         return(default(T));
     }
 }
Пример #4
0
 public TEvent Deserialize <TEvent>(string eventType, string serializedEvent) where TEvent : IDomainEvent
 {
     return(_jsonProvider.DeserializeObject <TEvent>(serializedEvent, eventType));
 }
 public T Deserialize <T>(string stringValue)
 {
     return(_jsonProvider.DeserializeObject <T>(stringValue));
 }