示例#1
0
        public async Task <T> GetAsync <T>(string requestUri)
        {
            var httpResponse = await _httpClient.GetAsync(requestUri);

            var content = await httpResponse.Content.ReadAsStringAsync();

            var deserializedItems = _jsonHelper.Deserialize <T>(content);

            return(deserializedItems);
        }
示例#2
0
 public void SerializeThenDeserialize()
 {
     for (var i = 0; i < Count; i++)
     {
         JsonHelper.Deserialize <Price>(JsonHelper.Serialize(Price));
     }
 }
        /// <summary>
        /// 将 JSON 字符串反序列化为对象。
        /// </summary>
        /// <typeparam name="T">对象类型。</typeparam>
        /// <param name="json">要反序列化的 JSON 字符串。</param>
        /// <returns>反序列化后的对象。</returns>
        public static T Deserialize <T>(string json)
        {
            if (s_JsonHelper == null)
            {
                throw new Exception("JSON helper is invalid.");
            }

            try
            {
                return(s_JsonHelper.Deserialize <T>(json));
            }
            catch (Exception exception)
            {
                if (exception is Exception)
                {
                    throw;
                }

                throw new Exception(string.Format("Can not convert to object with exception '{0}'.", exception.ToString()), exception);
            }
        }
        public Product[] GetData()
        {
            var jsonFilePath = _configuration.Configuration.JsonFilePath;


            Product[] products = _jsonHelper.Deserialize <Product[]>(_fileHelper.ReadTextFile(jsonFilePath));
            return(products);

            //debug code here//
            //string lines = "";
            //foreach (Product p in products)
            //{
            //    for (int i = 0; i<5; i++)
            //    {
            //        lines += p?.Reviews?[i].Customer + "\t" + p?.Reviews?[i].Comment + "\n";
            //    }
            //    //lines += p.Reviews?[0]?.Customer + "\t" + p.Reviews?[0] + "\n";
            //}
            //_fileHelper.WriteTextFile("C:/Users/nionsong/Desktop/output.txt", lines);

            //return products;
            //end debug code//
        }
        public Product[] GetData()
        {
            String jsonFilePath;

            if (ExecutionMode.IsRunningAsUwp())
            {
                jsonFilePath = Path.Combine(AppFolders.Current, "desktop", _configuration.Configuration.JsonFilePath);
            }
            else
            {
                jsonFilePath = _configuration.Configuration.JsonFilePath;
            }

            return(_jsonHelper.Deserialize <Product[]>(_fileHelper.ReadTextFile(jsonFilePath)));
        }
示例#6
0
        private static TextScenario GetTextScenario(DbWorkflowStepItem item, IJsonHelper jsonHelper)
        {
            Result <IEnumerable <Question> > result = jsonHelper.Deserialize <IEnumerable <Question> > (item.Content);

            if (result.IsFailure)
            {
                throw new Exception(string.Format("Could not deserialize TextScenario workflow step item content to IEnumerable<Question>. Code: {0}", item.Code));
            }

            return(new TextScenario {
                Id = item.Id,
                Code = item.Code,
                CultureCode = item.CultureCode,
                Questions = result.Value,
                LastModified = item.LastModified,
                DateCreated = item.DateCreated
            });
        }
示例#7
0
        private static SimpleQuestion GetSimpleQuestion(DbWorkflowStepItem item, IJsonHelper jsonHelper)
        {
            Result <Question> result = jsonHelper.Deserialize <Question> (item.Content);

            if (result.IsFailure)
            {
                throw new Exception(string.Format("Could not deserialize SimpleQuestion workflow step item content to Question. Code: {0}", item.Code));
            }

            return(new SimpleQuestion {
                Id = item.Id,
                Code = item.Code,
                CultureCode = item.CultureCode,
                Question = result.Value,
                LastModified = item.LastModified,
                DateCreated = item.DateCreated
            });
        }
示例#8
0
 /// <summary>
 /// 反序列化
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="json"></param>
 /// <returns></returns>
 public T Deserialize <T>(string json) where T : class
 {
     return(jsonHelper.Deserialize <T>(json));
 }
 public ConfigurationService(IFileHelper fileHelper, IJsonHelper jsonHelper)
 {
     Configuration = jsonHelper.Deserialize <ConfigurationModel>(fileHelper.ReadTextFile(ConfigurationFilePath));
 }
        public Product[] GetData()
        {
            var jsonFilePath = _configuration.Configuration.JsonFilePath;

            return(_jsonHelper.Deserialize <Product[]>(_fileHelper.ReadTextFile(_fileHelper.ActualPath + jsonFilePath)));
        }