我有包含“,”的字符串,需要将其序列化/反序列化为CSV。我已经能够正确地序列化它,但是当反序列化时,它总是错误的。这是我在java中的代码
List<String> header = ...
test1,
test2, test3 <-- string contains comma ,
test4
List<String> updatedHeaderList = Lists.transform(headerList, new Function<String, String> () {
public String apply(String input) {
return StringEscapeUtils.escapeCsv(input);
}
});
Joiner joiner = Joiner.on(separator);
stringBuilder = joiner.appendTo(stringBuilder, updatedHeaderList);
stringBuilder.append("\n");
return stringBuilder.toString();
当我检查序列化字符串时: test1,“test2 \,test3”,test4 看起来对我来说
然后我试着反序列化它:
Splitter.on(",").splitToList(resultString)
it returned list as
test1,
test2,
test3,
test4
我怎样才能将其反序列化为
test1
test2, test3
test4
感谢
答案 0 :(得分:4)