I'm parsing a csv file from google api with golang, the file is encoded in utf-16, code below try to read one record(skip header) and print the record, but it gives me the output like this which is weird:
, v=/09/20 00:35:42 k=Smartfren Andromax AD681H
I guess it's probably related with utf-16 encoding, but don't know the detail, here is the code: package main
import (
"encoding/csv"
"io"
"log"
"net/http"
"strings"
)
var url = "http://storage.googleapis.com/play_public/supported_devices.csv"
func main() {
resp, err := http.Get(url)
if err != nil {
return
}
defer resp.Body.Close()
r := csv.NewReader(resp.Body)
r.LazyQuotes = true
r.FieldsPerRecord = -1
// skip header
r.Read()
m := make(map[string]string)
for {
record, err := r.Read()
if err == io.EOF {
break
}
if err != nil {
log.Println(err)
continue
}
if len(record) >= 4 {
m[strings.TrimSpace(record[3])] = strings.TrimSpace(record[1])
for k, v := range m {
log.Printf("k=%s, v=%s
", k, v)
}
break
}
}
}