我有一个包含以下内容的 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();
}
但它失败了,因为"B"
csv 中存在。我收到以下错误:
引起:com.fasterxml.jackson.core.JsonParseException:意外字符('W'(代码 87)):预期的分隔符('"'(代码 34))或 [来源:(com.fasterxml .jackson.dataformat.csv.impl.UTF8Reader);行:2,列:43]
如何正确解析 csv 中的双引号?我试着玩弄,schema.withEscapeChar()
schema.withQuoteChar()
但我无法让它工作。