Newtonsoft Json Deserlize as C# Datagridview

被刻印的时光 ゝ 提交于 2019-12-23 15:14:13

问题


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?


回答1:


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#.



来源:https://stackoverflow.com/questions/30277998/newtonsoft-json-deserlize-as-c-sharp-datagridview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!