我有如下所示的 CSV 文件,
我使用“readAsText”或“readAsBinaryString”方法读取文件数据;
var fileInput = document.getElementById("csv"),
readFile = function () {
var reader = new FileReader();
reader.onload = function () {
document.getElementById('out').innerHTML = reader.result;
};
reader.readAsText(fileInput.files[0]);
};
fileInput.addEventListener('change', readFile);
reader.result will give the following result,
Version,IP Address,Hostname,data 1235FDRRG,A1,7.0(3)(2),1.1.1.1,admin,"
{""1"":""rollno"",""2"":""serialnumber""}"
这里,转义引号是 {""1"":""rollno"",""2"":""serialnumber""}
。
如何导入 CSV 文件而不转义引号?
我想要像{"1":"rollno","2":"serialnumber"}这样的数据
谁能帮我解决这个问题吗?
提前致谢。
最佳答案
您可以使用正则表达式替换该引号。
reader.result.replace(/(\"\")/g,'"').slice(1,-1);
之后你会得到与你想要的相同的结果 -
{"1":"卷号","2":"序列号"}
关于javascript - 导入不带转义引号的 csv javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52366045/