0

I'm new to C#, I have a API Console Application connect to MySQL in C#:

Example: "http://localhost:12345/api/apiname/something" enter image description here

I have created a Windows Form project in the same solution as Console Application API. I created a Button to GET data from that API but i don't know how to put it in and show results on datagridview.

Sorry if my English not good. enter image description here

I have tried searching a lot on google and youtube but couldn't find a solution to the problem :(

slaakso
  • 8,331
  • 2
  • 16
  • 27
Lil s0uxz
  • 1
  • 2
  • Put into a DataTable than make the table the DataSource of the DGV : datagridview1.DataSource = dt; – jdweng Mar 09 '23 at 07:31
  • So you want to add an item in json format on each datagrid row? – Radu Hatos Mar 09 '23 at 08:42
  • Look at the accepted answer on this page: https://stackoverflow.com/questions/19910476/c-sharp-parsing-json-array-of-objects. I think that is the solution for you – Radu Hatos Mar 09 '23 at 08:48

1 Answers1

0

Here are some steps you can follow:

  1. Call the remote api and get a string with the json data (I think you've done that already).
  2. Create some classes with the same structure as the json data. You can write them manually or use tools for that. Some options are json2csharp or visual studio itself.
  3. Deserialize the json code to objects using Newtonsoft or System.Text.Json.
  4. I guess you have some kind of data list in your json you want to show in the grid. Assign the deserialized list to the DataSource property of the grid and you're done.
Marco Regueira
  • 1,045
  • 8
  • 17