Hallo ich habe ein Problem mit CSV-Datei in JavaScript zu analysieren. Struktur CSV unterSlice String von CSV JavaScript
<code>
date, hours, text
2004-05-04,05:22, Sample text, with coma
2005-05-04,05:22:00, Another Sample text, with coma
2006-05-04,05:22, Third Sample text, with coma
</code>
dieses CSV zu analysieren, I-Code verwenden, unter
<code>
$.ajax({
type: "GET",
url: "data.csv",
dataType: "text",
success: function(data) {processData(data);}
});
function processData(csv) {
var allTextLines = csv.split(/\r\n|\n/);
//console.log(allTextLines);
var lines = [];
while (allTextLines.length) {
//console.log(allTextLines);
lines.push(allTextLines.shift().split(","));
}
console.log(lines);
}
</code>
Das Problem ist, wenn ich innerhalb Text Komma habe ich haben Array wie diese
<code>
lines[0]=['2004-05-04']['05:22'][Sample text][with comma];
</code>
Meine Frage ist, , wie man dies in ein Array wie dieses umwandelt:
<code>
lines[0]=['2004-05-04']['05:22'][Sample text, with coma];
</code>
Vielen Dank für Ihre Hilfe!
Mögliche Duplikat [Wie kann ich eine CSV-Zeichenfolge mit Javascript analysieren, das Komma in Daten enthalten?] (Https://stackoverflow.com/questions/8493195/how-can- i-parse-a-csv-zeichenfolge-with-javascript-which-enthält-comma-in-data) – str
Hat Ihre CSV konsistent nur 3 Spalten? –
Ja, ich habe 3 Spalten, aber in der Textspalte kann mehr Koma sein – breakbit