我很難包裝我的頭周圍如何解析一個csv文件並將其張貼到web服務使用scala。需要幫助,試圖解析文件和創建scala地圖
基本思路是我需要從csv文件創建後參數。標題將是參數,下面的行將是值,即。
例如CSV
firstname, lastname, age, weight, height
John, Doe, 30, 180, 72
Mary, Jane, 28, 120, 64
這將映射到參數 firstname=John&lastname=Doe&age=30&weight=180&height=72
等
我有以下階分析數據,但似乎無法找出下一步做什麼:
val lines = fromFile("runners/io/m2m/naf/ARDS.csv").getLines
for ((line, cnt) <- lines.zipWithIndex) {
if (cnt == 0) {
for((header, i) <- CsvParser.parse(line).view.zipWithIndex){
}
}else {
for((data, i) <- CsvParser.parse(line).view.zipWithIndex) {
}
}
}
店頭在由'i'索引的映射,然後爲每個'data'項,查找地圖並輸出header = data。需要更多幫助? – milan 2012-01-16 19:03:53
是的我想我可以使用不可變的地圖等,但它似乎應該有一個功能的方法來解決這個問題。 – chiappone 2012-01-16 19:13:10
哦,它沒有在問題中指定,你正在尋找一個'功能的方法'.. – milan 2012-01-16 19:14:13