Newtonsoft Json Deserlize作为C#Datagridview [英] Newtonsoft Json Deserlize as C# Datagridview
本文介绍了Newtonsoft Json Deserlize作为C#Datagridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在使用Newtonsoft Json插件时遇到了一些问题.我想使用Json填充datagridview,但不知道如何.在Newtonsoft Json的文档中,我得到了带有数据表的示例,但是如果我尝试此示例,我将得到错误.
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.
这是我的杰森:
[
{
"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"
}
]
我尝试使用此示例和也许有人可以帮忙吗?
推荐答案
JSON是一个数组,而不是对象,因此将其反序列化为DataTable
:
The JSON is an array, not an object, so deserialize it as a DataTable
:
var dataTable = JsonConvert.DeserializeObject<DataTable>(json);
然后使用以下答案将DataTable
添加到DataGridView
:
Then add the DataTable
to the DataGridView
using this answer: Moving data from datatable to datagridview in C#.
这篇关于Newtonsoft Json Deserlize作为C#Datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文