我正在使用Csv Type Provider从本地csv文件中读取数据。
我想将数据导出为json,因此我将每行使用带有JsonConvert.SerializeObject(x)
的json.net库进行序列化。
问题是每一行都被建模为一个元组,这意味着列标题在序列化时不会成为属性名称。相反,我得到Item1 =" ...&#34 ;;项目2 =" ..."等
如果没有'手动滚动'我如何导出到Json?用于保存值和维护属性名称的类/记录类型?
答案 0 :(得分:1)
The TypeProvider works by providing compile time type safety. The actual code that is compiled maps (at compile time) the nice accessors to tupled values (for performance reasons, I guess). So at run time the JSON serializer sees tuples only.
AFAIK there is no way around hand-rolling records. (That is unless we eventually get type providers that are allowed to take types as parameters which would allow a Lift<T>
-type provider or the CSV type provider implementation is adjusted accordingly.)