我有以下CSV文件,其JSON字段可能包含分隔符:
2.0.0|2018-11-04 10:10:14,471|eventname|{"fieldA":"value with separator | inside","fieldB":"54321"}|123456|empty
我试图使用以下代码来获取整个字段,但是它总是被内部分隔符分割:
String csvLine = "2.0.0|2018-11-04 10:10:14,471|eventname|{\"fieldA\":\"value with separator | inside\",\"fieldB\":\"54321\"}|123456|empty";
CsvParserSettings settings = new CsvParserSettings();
settings.getFormat().setDelimiter("|");
settings.getFormat().setQuote('"');
settings.getFormat().setQuoteEscape('\\');
CsvParser parser = new CsvParser(settings);
String[] row = parser.parseLine(csvLine);
System.out.println(row[3]);
预期输出:
{"fieldA":"value with separator | inside","fieldB":"54321"}
当前输出:
{"fieldA":"value with separator
当文件位于引号之间时,如何告诉CSV解析器不拆分?