我正在使用Commons CSV来解析与电视节目相关的 CSV 内容。其中一个节目的节目名称包含双引号;
116,6,2,29 Sep 10,""JJ"(60 分钟)"," http://www.tvmaze.com/episodes/4855/criminal-minds-6x02-jj "
节目名称是“JJ”(60 分钟),它已经用双引号括起来了。这是在封装的标记和分隔符之间抛出 IOException java.io.IOException: (line 1) invalid char。
ArrayList<String> allElements = new ArrayList<String>();
CSVFormat csvFormat = CSVFormat.DEFAULT;
CSVParser csvFileParser = new CSVParser(new StringReader(line), csvFormat);
List<CSVRecord> csvRecords = null;
csvRecords = csvFileParser.getRecords();
for (CSVRecord record : csvRecords) {
int length = record.size();
for (int x = 0; x < length; x++) {
allElements.add(record.get(x));
}
}
csvFileParser.close();
return allElements;
CSVFormat.DEFAULT 已设置 withQuote('"')
我认为这个 CSV 的格式不正确,因为“”JJ“(60 分钟)”应该是“”“JJ”“(60 分钟)”——但是有没有办法让 commons CSV 来处理这个或者我需要手动修复这个条目?
附加信息:其他节目名称在 CSV 条目中包含空格和逗号,并放在双引号内。