我的 Windows 窗体应用程序上有一个 datagridview,它接受用户的输入。我想使用 JSON 来存储此输入,并尝试将来自 datagridview 的输入序列化为 JSON。
到目前为止我有:
private void button2_Click(object sender, EventArgs e)
{
string output = JsonConvert.SerializeObject(this.dataGridView1);
System.IO.File.WriteAllText("json.json", output);
}
然而,在尝试序列化 datagridview 时似乎出了点问题(之前我的印象是任何对象都可以转换?)。这是否意味着我必须先将 datagridview 转换为数组或列表或类似的东西才能序列化它?
最佳答案
始终序列化数据本身而不是 View 。
在这种情况下,您必须序列化 DataGridView
的 DataSource
属性。
关于c# - 将 dataGridView 序列化为 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40741841/