Example #1
0
        public TResult Get <TResult>(string subUri, IJsonReader <TResult> customConverter = null)
        {
            var jsonString = this.GetString(subUri);

            var result = customConverter == null?JsonConvert.DeserializeObject <TResult>(jsonString) :
                             customConverter.ReadJson(jsonString);

            if (result == null)
            {
                throw new JsonException($"The json string {Environment.NewLine + jsonString + Environment.NewLine} could not be" +
                                        $"converted to the type {typeof(TResult).Name}.");
            }

            return(result);
        }
Example #2
0
        public async Task <TResult> Get <TResult>(string subUri, IJsonReader <TResult> customConverter = null)
        {
            var jsonString = await this.GetString(subUri);

            TResult result = customConverter == null ?  await Task.Factory.StartNew(() => JsonConvert.DeserializeObject <TResult>(jsonString)) : await Task.Factory.StartNew(() => customConverter.ReadJson(jsonString));

            if (result == null)
            {
                throw new JsonException($"The json string {Environment.NewLine + jsonString + Environment.NewLine} could not be" +
                                        $"converted to the type {typeof(TResult).Name}.");
            }

            return(result);
        }