问题描述
我正在尝试找到一种方法来对具有一个数据表的数据集进行序列化和反序列化为JSON,并使用JSON.NET从JSON返回到数据集/数据表,但是我发现的所有示例和示例都仅从一个序列化数据集或数据表转换为JSON,决不会两种方式.我们有一个处理XML序列化数据集和数据表的系统,我们仍然需要保留该格式,但是允许某些UI视图将数据呈现为JSON.
I am trying to find a way to both serialize and deserialize a dataset with one datatable to JSON and from JSON back to a dataset / datatable using JSON.NET, however all the samples and examples I have found are only serializing from a dataset or datatable to JSON and never two way. We have a system that deals with XML serialized datasets and datatables that we need to still retain in that format but allow certain UI views to render the data as JSON.
数据可以为空值,并且是有效的.
Data can have null values and that's valid.
任何帮助将不胜感激.
Example (One way serialization):
http://www.west-wind.com/weblog/posts/2008/Sep/03/DataTable-JSON-Serialization-in-JSONNET-and-JavaScriptSerializer
推荐答案
以下链接是Newtonsoft.Json.Converters.DataTableConverter.cs的源代码,它可以完成您想要的工作,这很简单,而且似乎是最佳途径
The following link is to the source for Newtonsoft.Json.Converters.DataTableConverter.cs which does what you want, it's pretty straight forward and seems like the best route.
这篇关于如何执行与JSON之间的数据表的序列化和反序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!