我有一个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()一起玩,但是我没能让它开始工作。
发布于 2019-07-07 06:51:57
在模式上使用withoutQuoteChar()处理csv内容中的双引号,即
CsvSchema.emptySchema().withHeader().withColumnSeparator('|').withNullValue("").withoutQuoteChar();https://stackoverflow.com/questions/47552871
复制相似问题