当前位置: 首页>>代码示例>>C#>>正文


C# HttpClient.GetJsonAsync方法代码示例

本文整理汇总了C#中HttpClient.GetJsonAsync方法的典型用法代码示例。如果您正苦于以下问题:C# HttpClient.GetJsonAsync方法的具体用法?C# HttpClient.GetJsonAsync怎么用?C# HttpClient.GetJsonAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HttpClient的用法示例。


在下文中一共展示了HttpClient.GetJsonAsync方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetArticleAsync

        public async Task<DataResultBase<Article>> GetArticleAsync(Feed feed)
        {
            if (feed == null)
            {
                throw new ArgumentNullException(nameof(feed));
            }

            string url = string.Format(ArticleTemplate, feed.Id);
            using (HttpClient client = new HttpClient())
            {
                return await client.GetJsonAsync<DataResultBase<Article>>(new Uri(url));
            }
        }
开发者ID:h82258652,项目名称:SoftwareKobo.U148For10,代码行数:13,代码来源:FeedService.cs

示例2: GetFeedListAsync

        public async Task<DataResultBase<ResultList<Feed>>> GetFeedListAsync(FeedCategory category, int page = 1)
        {
            if (Enum.IsDefined(typeof(FeedCategory), category) == false)
            {
                throw new ArgumentException($"{nameof(category)} is not defined.", nameof(category));
            }
            if (page <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(page), "page should greater than zero.");
            }

            string url = string.Format(CategoryListTemplate, (int)category, page);
            using (HttpClient client = new HttpClient())
            {
                return await client.GetJsonAsync<DataResultBase<ResultList<Feed>>>(new Uri(url));
            }
        }
开发者ID:h82258652,项目名称:SoftwareKobo.U148For10,代码行数:17,代码来源:FeedService.cs

示例3: GetCommentsAsync

        public async Task<DataResultBase<ResultList<Comment>>> GetCommentsAsync(Feed feed, int page = 1)
        {
            if (feed == null)
            {
                throw new ArgumentNullException(nameof(feed));
            }
            if (page <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(page), "page should greater than zero.");
            }

            string url = string.Format(GetCommentTemplate, feed.Id, page);
            url = url + "?t=" + DateTime.Now.Ticks;
            using (HttpClient client = new HttpClient())
            {
                return await client.GetJsonAsync<DataResultBase<ResultList<Comment>>>(new Uri(url));
            }
        }
开发者ID:h82258652,项目名称:SoftwareKobo.U148For10,代码行数:18,代码来源:CommentService.cs

示例4: GetSearchResultsAsync

        public Task<DataResultBase<ResultList<Feed>>> GetSearchResultsAsync(string keyword, int page = 1)
        {
            if (keyword == null)
            {
                throw new ArgumentNullException(nameof(keyword));
            }
            if (keyword.Length <= 0)
            {
                throw new ArgumentException("query could not be empty.", nameof(keyword));
            }
            if (page <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(page), "page should greater than zero.");
            }

            string url = string.Format(SearchTemplate, page, keyword);
            using (HttpClient client = new HttpClient())
            {
                return client.GetJsonAsync<DataResultBase<ResultList<Feed>>>(new Uri(url));
            }
        }
开发者ID:h82258652,项目名称:SoftwareKobo.U148For10,代码行数:21,代码来源:SearchService.cs


注:本文中的HttpClient.GetJsonAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。