How to display JSON data in a DataGridView in WinForms?

后端 未结 3 1080
隐瞒了意图╮
隐瞒了意图╮ 2020-12-14 13:26

This is the JSON data that I have:

{"testId":1,"testName":"HTML","minScore":20,"score":40,"date&qu

3条回答
  •  死守一世寂寞
    2020-12-14 14:14

    1. using Newtonsoft.Json.Linq;
    2. using System.Net;
    void get_response()
    {
         WebClient wp = new WebClient();
         string url="your json url";
         var response=wp.DownloadString(url)
         get_data(response)
    }
    
    
    void get_data(string response)
    {
        datagridview.Rows.clear();`enter code here`
        JArray fetch= JArray.Parse(response);
        if(fetch.Count()>0)
        {
            for(int i=0;datagridview.Rows.Count>i;i++)
            {
                int n=datagridview.Rows.Add();
                datagridview.Rows[n].Cells[0].Value=fetch[i]["Json 
                ObjectName1"].ToString();
            }
        }
    }
    

提交回复
热议问题