如何编写包含CSVHelper数组的对象?
在 C#/.net 中,我将 Api 请求反序列化为对象。该对象包含数组,当我使用 csvHelper 将其写入文件时,如下所示: https://joshclose.github.io/CsvHelper/examples/writing/write-class-objects/ 该对象被写入 csv,但没有数组。
我序列化到的对象如下所示:
public class MyMainObject
{
public int Id { get; set; }
public string Name { get; set; }
public MyMissingArray[] data { get; set; }
}
public class MyMissingArray{
public string id { get; set; }
public string value { get; set; }
}
将这些数组放入 csv 文件的最佳方法是什么?
- 创建类映射? : https://joshclose.github.io/CsvHelper/examples/configuration/ class-maps/
- 使用 foreach-loops 创建自定义逻辑编写:https://github.com/JoshClose/CsvHelper/issues/765
- 或者是否有 < em>令人窒息如何做到这一点?
- 如何将 MyMissingArray 放入最终的 csvFile 中?
in C#/.net I deserialize a Api-request into a object. This object contains arrays, when i write it to file using csvHelper like this: https://joshclose.github.io/CsvHelper/examples/writing/write-class-objects/
The object is written to csv, but without the arrays.
My object which i serialize into, look like this:
public class MyMainObject
{
public int Id { get; set; }
public string Name { get; set; }
public MyMissingArray[] data { get; set; }
}
public class MyMissingArray{
public string id { get; set; }
public string value { get; set; }
}
What is the best way to get these arrays into the csv file?
- Create ClassMap? : https://joshclose.github.io/CsvHelper/examples/configuration/class-maps/
- Create custom logic writing with foreach-loops : https://github.com/JoshClose/CsvHelper/issues/765
- Or is there a smother way to do this?
- How do i get the MyMissingArray into the final csvFile?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为最简单的方法是在
ClassMap
中使用Convert
。您可以按照您想要的方式格式化数据
。I think the easiest way will be to use
Convert
in aClassMap
. You can format thedata
how you want it.