Newtonsoft Json Deserlize as C # Datagridview

I have some problems using Newtonsoft Json Plugin. I want to populate a datagridview using Json, but don't know how to do it. In the Newtonsoft Json documentation, I get an exmaple with a datatable, but if I try this sample, I just get errors.

This is my Json:

[
    {
        "id": "17",
        "name": "Filename",
        "author": "unknown",
        "size": "3.1MB",
        "pfad": "ftp://path/Filename",
        "Filetoken": "6747rzuzur6urzut766754677"
    },
    {
        "id": "20",
        "name": "Filename",
        "author": "unknown",
        "size": "3.1MB",
        "pfad": "ftp://path/Filename",
        "Filetoken": "6747rzuzur6urzut766754677"
    }
]

I tried using this example and this

Can anyone please help?

+4
source share
1 answer

JSON is an array, not an object, so deserialize it as DataTable:

var dataTable = JsonConvert.DeserializeObject<DataTable>(json);

Then add DataTablein DataGridViewwith this answer: Moving data from datatable to datagridview in C # .

+4
source

All Articles