Sevenlive
Sevenlive

Reputation: 43

Newtonsoft Json Deserlize as C# Datagridview

I have some issues using the Newtonsoft Json Plugin. I want to fill a datagridview using Json but dont know how. In the Documentation of Newtonsoft Json i get an exmaple with 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 to use this example and this

Maybe anyone can help?

Upvotes: 4

Views: 2953

Answers (1)

dbc
dbc

Reputation: 116991

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

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

Then add the DataTable to the DataGridView using this answer: Moving data from datatable to datagridview in C#.

Upvotes: 5

Related Questions