Home > Mobile >  c# how to read json when button is clicked, how to print to table after reading?
c# how to read json when button is clicked, how to print to table after reading?

Time:09-26

I want to change my datagrid table, which I filled when the form is opened, by calling another json file with a button. how will I do? how to read json when button is clicked, how to print to table after reading?

private void button3_Click(object sender, EventArgs e)
{
    dataGridView1.Rows.Clear();
    parameters. Clear);
    dataGridView1.Refresh();

    string dosya_yolu2 = Application.StartupPath   "Files\\defaultValue.json";
    //Okuma işlem yapacağımız dosyanın yolunu belirtiyoruz.
    FileStream dv2 = new FileStream(dosya_yolu2, FileMode.Open, FileAccess.Read);
    //Bir file stream nesnesi oluşturuyoruz. 1.parametre dosya yolunu,
    //2.parametre dosyanın açılacağını,
    //3.parametre dosyaya erişimin veri okumak için olacağını gösterir.
    StreamReader sw2 = new StreamReader(dv2);
    //Okuma işlemi için bir StreamReader nesnesi oluşturduk.
    string yazi2 = sw2.ReadToEnd();
    //Satır satır okuma işlemini gerçekleştirdik ve ekrana yazdırdık
    //Son satır okunduktan sonra okuma işlemini bitirdik
    sw2.Close();
    dv2.Close();
    //İşimiz bitince kullandığımız nesneleri iade ettik.

}


    

CodePudding user response:

You have to deserialize the json data (create a model for that) and after that you can view it in data grid view control.

CodePudding user response:

Here is an example using enter image description here

  •  Tags:  
  • c#
  • Related