zoukankan      html  css  js  c++  java
  • winform解析json API数据

    {
      "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;              

                        }

    }

    }

  • 相关阅读:
    springMVC学习--RESTful支持
    Java中的值传递和引用传递
    SpringMVC学习--json
    SpringMVC学习--文件上传
    SpringMVC学习--异常处理器
    SpringMVC学习--数据回显
    SpringMVC学习--校验
    SpringMVC学习--参数绑定
    SpringMVC学习--功能完善
    SpringMVC学习--springmvc和mybatis整合
  • 原文地址:https://www.cnblogs.com/panjuan/p/4500959.html
Copyright © 2011-2022 走看看