JSON

Windows 10开发基础(7)

字号+ 作者:H5之家 来源:H5之家 2015-11-24 18:58 我要评论( )

请求JSON数据: private async void InitDataJson() { HttpClient httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Accept.Add(new HttpMediaTypeWithQualityHeaderValue(application/json)); Ht

请求JSON数据:

private async void InitDataJson() { HttpClient httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Accept.Add(new HttpMediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = await httpClient.GetAsync(new Uri(":64339/api/books")); response.EnsureSuccessStatusCode(); string result = await response.Content.ReadAsStringAsync(); List<Books> bookslist = new List<Books>(); JsonArray arrays = JsonArray.Parse(result); for (int i = 0; i < arrays.Count; i++) { JsonObject obj = arrays.GetObjectAt((uint)i); bookslist.Add(new Books() { book_Name =obj.GetNamedString("book_Name"), book_Author = obj.GetNamedString("book_Author"), book_Isbn = obj.GetNamedString("book_Isbn"), book_cate =obj.GetNamedString("book_cate"), book_Press = obj.GetNamedString("book_Press"), book_Rressdate = obj.GetNamedString("book_Rressdate"), book_Remain = Convert.ToInt32(obj.GetNamedNumber("book_Remain")) }); } listView.ItemsSource = bookslist; }

Book.cs:

public class Books { public int book_Id { get; set; } public string book_Name { get; set; } public string book_Author { get; set; } public string book_Isbn { get; set; } public string book_cate { get; set; } public string book_Press { get; set; } public string book_Rressdate { get; set; } public int book_Remain { get; set; } } View Code

运行结果:

Windows 10开发基础——XML和JSON (二)

借助于ASP.NET Web API,我们最终将SQL Server数据库中的数据通过UWP应用进行了展示。(我发现最后的这个图表示的意思有点不够,懒得换了,懒)

好了,这就是本次的全部内容了,貌似有点乱,要Demo的留邮箱。太晚了,睡觉了,晚安!

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • ASP.NET Web API 2 返回 Json格式

    ASP.NET Web API 2 返回 Json格式

    2016-02-10 17:18

  • wordpress 4.4 禁用REST API/移除wp

    wordpress 4.4 禁用REST API/移除wp

    2016-01-18 18:10

  • 突袭HTML5之Javascript API扩展3—本地存储全新体验

    突袭HTML5之Javascript API扩展3—本地存储全新体验

    2015-11-25 09:21

  • Java Json API:Gson使用简单入门

    Java Json API:Gson使用简单入门

    2015-11-23 17:30

网友点评
r