使用 jackson-dataformat-csv 从 csv 解析双引号
Parsing double quote from csv using jackson-dataformat-csv
我有一个包含以下内容的 csv
EANHotelID|SequenceNumber|Name|Address1|Address2|City|StateProvince|PostalCode|Country|Latitude|Longitude|AirportCode|PropertyCategory|PropertyCurrency|StarRating|Confidence|SupplierType|Location|ChainCodeID|RegionID|HighRate|LowRate|CheckInTime|CheckOutTime
541454|99999999|Hotel Maan Residency|"B" Wing, Gopal Palace, opp. ocean park|Naherunagar-Satellite Road|Ahmedabad||380 015|IN|23.02266|72.53842|AMD|1|INR|3.0||ESR|Near Kankaria Lake|||0|0|10:00 AM|10:00 AM
现在我尝试使用以下代码将此 csv 中的每一行作为对象读取
CsvMapper mapper = new CsvMapper();
mapper.findAndRegisterModules();
File csvFile = new File("D:\ActivePropertyList.txt.bak2");
CsvSchema schema = CsvSchema.emptySchema().withHeader().withColumnSeparator('|').withNullValue("");
MappingIterator<Map<String,String>> it = mapper.readerFor(Map.class).with(schema)
.readValues(csvFile);
while (it.hasNextValue()) {
Map<String,String> value = it.nextValue();
}
但由于 csv 中存在 "B"
而失败。我收到以下错误:
Caused by: com.fasterxml.jackson.core.JsonParseException: Unexpected
character ('W' (code 87)): Expected separator ('"' (code 34)) or
end-of-line at [Source:
(com.fasterxml.jackson.dataformat.csv.impl.UTF8Reader); line: 2,
column: 43]
如何正确解析csv中的双引号?我试着玩弄 schema.withEscapeChar()
schema.withQuoteChar()
但我无法让它工作。
在架构上使用 withoutQuoteChar()
来处理 csv 内容中的双引号,即
CsvSchema.emptySchema().withHeader().withColumnSeparator('|').withNullValue("").withoutQuoteChar();
我有一个包含以下内容的 csv
EANHotelID|SequenceNumber|Name|Address1|Address2|City|StateProvince|PostalCode|Country|Latitude|Longitude|AirportCode|PropertyCategory|PropertyCurrency|StarRating|Confidence|SupplierType|Location|ChainCodeID|RegionID|HighRate|LowRate|CheckInTime|CheckOutTime
541454|99999999|Hotel Maan Residency|"B" Wing, Gopal Palace, opp. ocean park|Naherunagar-Satellite Road|Ahmedabad||380 015|IN|23.02266|72.53842|AMD|1|INR|3.0||ESR|Near Kankaria Lake|||0|0|10:00 AM|10:00 AM
现在我尝试使用以下代码将此 csv 中的每一行作为对象读取
CsvMapper mapper = new CsvMapper();
mapper.findAndRegisterModules();
File csvFile = new File("D:\ActivePropertyList.txt.bak2");
CsvSchema schema = CsvSchema.emptySchema().withHeader().withColumnSeparator('|').withNullValue("");
MappingIterator<Map<String,String>> it = mapper.readerFor(Map.class).with(schema)
.readValues(csvFile);
while (it.hasNextValue()) {
Map<String,String> value = it.nextValue();
}
但由于 csv 中存在 "B"
而失败。我收到以下错误:
Caused by: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('W' (code 87)): Expected separator ('"' (code 34)) or end-of-line at [Source: (com.fasterxml.jackson.dataformat.csv.impl.UTF8Reader); line: 2, column: 43]
如何正确解析csv中的双引号?我试着玩弄 schema.withEscapeChar()
schema.withQuoteChar()
但我无法让它工作。
在架构上使用 withoutQuoteChar()
来处理 csv 内容中的双引号,即
CsvSchema.emptySchema().withHeader().withColumnSeparator('|').withNullValue("").withoutQuoteChar();