FileHelpers:分隔符“|”田野后找不到
FileHelpers: The delimiter '|' can´t be found after the field
我有一个巨大的 CSV 文件 (1GB),看起来像这样:
1140|2017|0213065852|2001|99|Ä‚/ŮŌçlš˝Ă_Âá'ÄǸ|-3858,18|4015,36|100,17|19,34|0,00|0,00|0,00|40,00|0,00|0,00|0,00|32,57|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|12|12|74|18|24620,65|11903,96|29385,35|10993,94|0,00|-2520,88|0|0100|301|02|0302|N|N|N| | |2001-12-27 00:00:00|N|1140|1313|BG4CSXF0| |2002-01-01 00:28:13| |0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00
1140|2017|0213065852|2002|99|ľë¸Â‰_gÂýľ)Ľ¸ů_°Ë
…p'™m'î'Ä_|-3799,76|3982,22|461,66|1,48|0,00|0,00|0,00|0,00|0,00|0,00|0,00|100,23|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|27|43|189|20|40140,74|48835,00|69605,32|19312,00|0,00|-3427,87|0|0100|301|02|0303|N|N|N| | |2002-12-27 00:00:00|N|1140|1313|BG4CSXF0| |2003-01-01 01:35:56| |0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00
当我尝试使用以下代码使用 FileHelpers 读取此文件时:
FileHelperEngine engine = new FileHelperEngine(typeof(BGDTMDF));
BGDTMDF[] tab = (BGDTMDF[])engine.ReadFile(path);
我收到一个错误:
The delimiter '|' can´t be found after the field 'MDF_SALDOS_MEDIOS' at line 2 (the record has less fields, the delimiter is wrong or the next field must be marked as optional).
我的 class 看起来像:
[DelimitedRecord("|")]
public class BGDTMDF
{
public string MDF_ENTIDAD;
public string MDF_CENTRO_ALTA;
public string MDF_CUENTA;
public string MDF_ANIO;
public string MDF_MES;
[FieldNullValue("def")]
public string MDF_SALDOS_MEDIOS;
[FieldNullValue("def")]
public string MDF_SALDO_DISPUE;
public string MDF_SALDO_MAX_DEU;
public string MDF_INTE_COBRAD;
public string MDF_INTE_PAGADO;
public string MDF_IMPU_RETENI;
}
(这个class只有一部分(这么大)。)
有什么帮助吗?
我的解决方案是将 class 中的所有字段标记为 [FieldOptional]。
我有一个巨大的 CSV 文件 (1GB),看起来像这样:
1140|2017|0213065852|2001|99|Ä‚/ŮŌçlš˝Ă_Âá'ÄǸ|-3858,18|4015,36|100,17|19,34|0,00|0,00|0,00|40,00|0,00|0,00|0,00|32,57|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|12|12|74|18|24620,65|11903,96|29385,35|10993,94|0,00|-2520,88|0|0100|301|02|0302|N|N|N| | |2001-12-27 00:00:00|N|1140|1313|BG4CSXF0| |2002-01-01 00:28:13| |0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00
1140|2017|0213065852|2002|99|ľë¸Â‰_gÂýľ)Ľ¸ů_°Ë
…p'™m'î'Ä_|-3799,76|3982,22|461,66|1,48|0,00|0,00|0,00|0,00|0,00|0,00|0,00|100,23|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|27|43|189|20|40140,74|48835,00|69605,32|19312,00|0,00|-3427,87|0|0100|301|02|0303|N|N|N| | |2002-12-27 00:00:00|N|1140|1313|BG4CSXF0| |2003-01-01 01:35:56| |0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00
当我尝试使用以下代码使用 FileHelpers 读取此文件时:
FileHelperEngine engine = new FileHelperEngine(typeof(BGDTMDF));
BGDTMDF[] tab = (BGDTMDF[])engine.ReadFile(path);
我收到一个错误:
The delimiter '|' can´t be found after the field 'MDF_SALDOS_MEDIOS' at line 2 (the record has less fields, the delimiter is wrong or the next field must be marked as optional).
我的 class 看起来像:
[DelimitedRecord("|")]
public class BGDTMDF
{
public string MDF_ENTIDAD;
public string MDF_CENTRO_ALTA;
public string MDF_CUENTA;
public string MDF_ANIO;
public string MDF_MES;
[FieldNullValue("def")]
public string MDF_SALDOS_MEDIOS;
[FieldNullValue("def")]
public string MDF_SALDO_DISPUE;
public string MDF_SALDO_MAX_DEU;
public string MDF_INTE_COBRAD;
public string MDF_INTE_PAGADO;
public string MDF_IMPU_RETENI;
}
(这个class只有一部分(这么大)。)
有什么帮助吗?
我的解决方案是将 class 中的所有字段标记为 [FieldOptional]。