使用Papa Parse保留引号

时间:2017-03-15 17:47:20

标签: papaparse

我正在使用Papa解析库,但似乎无法保持引号。

我试过了:

var parseMe = '"my","header","row","is","here"\r\n"one","two","three","four","five"\r\n"six","seven","eight","nine","ten"';

var pConfig = {"skipEmptyLines":true,
 "delimiter":",",
 "quotes":false}

 console.log(JSON.stringify(Papa.parse( parseMe, pConfig ).data));

https://jsfiddle.net/5w9wwqwx/

但没有运气。我回来了:

[["my","header","row","is","here"],["one","two","three","four","five"],["six","seven","eight","nine","ten"]]

但我期待的是:

[["\"my"\","\"header"\","\"row"\","\"is"\","\"here"\"],.....

e.g。所有报价仍然在输出中。

我认为将引号设置为false会得到papa解析以保持字符串中的双引号但没有运气。如果我能帮忙的话,我不想逃避引号。我想我可以把它们放回去:P。

1 个答案:

答案 0 :(得分:0)

默认情况下,PapaParse使用"作为quoteChar,所以如果字段被引用"此值已删除。如果你想保留"解析文件时,必须使用不同的quoteChar(例如')。

这样可以解决问题:

var parseMe = '"my","header","row","is","here"\r\n"one","two","three","four","five"\r\n"six","seven","eight","nine","ten"';

var pConfig = {"skipEmptyLines":true,  "delimiter":",", "quoteChar": "'"}

 console.log(JSON.stringify(Papa.parse( parseMe, pConfig ).data));