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;

}

}

}

上一篇:MySQL多实例配置


下一篇:解析JSON、扩展Fiddler