码迷,mamicode.com
首页 > Windows程序 > 详细

winform解析json API数据

时间:2015-05-13 18:31:26      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:

{
  "retCode" : "SUCCESS",
  "msg" : "",
  "data" : {
    "List" : [ {  

      "ID " : 1,
      "description" : "",
    } ]
  }
}

 

  public class Class1     {         public string retCode{ get; set; }

        public string msg { get; set; }

        public Class3 data { get; set; }     }

 

 

   public class Class2     {      

        public string description { get; set; }

     }

 

 public class Class3
    {
        public Class2[] List { get; set; }
    }

 

 

 private async void gettest()       

  {             using (var Client = new HttpClient())         

    {                 Client.BaseAddress = new Uri("");          

       Client.DefaultRequestHeaders.Accept.Clear();        

         Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));          

       Client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", "");

                HttpResponseMessage response = await Client.GetAsync("");              

   if (response.IsSuccessStatusCode == true)            

     {                  

   Class1 result = null;         

            Class3 cl = null;         

            Class2 c2 = new Class2();              

       string json = await response.Content.ReadAsStringAsync();          

           result = JsonConvert.DeserializeObject<Class1>(json);          

           cl = result.data;           

          for (int i = 0; i < cl.List.Length; i++)            

         {                      

   c2.id = cl.List[i].id;              

                    }

}

}

 

winform解析json API数据

标签:

原文地址:http://www.cnblogs.com/panjuan/p/4500959.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!