【发布时间】:2021-07-05 17:08:33
【问题描述】:
在写入 CSV 文件时,它没有值 red 和 small
例子:
输入json文件:
[
{
"id": 1,
"name": "Mike",
"features": {
"colors": [
"blue"
],
"sizes": [
"big"
]
}
},
{
"id": 1,
"name": "Jose",
"features": {
"colors": [
"blue",
"red"
],
"sizes": [
"big",
"small"
]
}
}
]
输出 csv 文件:
id;name;features_colors_0;features_sizes_0
1;Mike;blue;big
1;Jose;blue;big
代码:
using ChoETL;
using System.IO;
namespace TestJsonToCsv
{
class Program
{
static void Main(string[] args)
{
var jsonPath = @"C:\Users\xxx\Downloads\test_array.json";
var csvPath = Path.ChangeExtension(jsonPath, "csv");
var config = new ChoJSONRecordConfiguration();
config.Encoding = System.Text.Encoding.UTF8;
using (var r = new ChoJSONReader(jsonPath, config))
{
using (var w = new ChoCSVWriter(csvPath).WithFirstLineHeader())
{
w.Write(r);
}
}
}
}
}
库版本:
ChoETL - 1.2.1.14
ChoETL.JSON - 1.2.1.14
问题参考 - https://github.com/Cinchoo/ChoETL/issues/138
【问题讨论】: