golang csv parse error on line 1, column 1: bare “ in non-quoted-field

问题

	csvFile, _ := os.Open("file.csv")
	reader := csv.NewReader(csvFile)
	records, err := reader.ReadAll()
	if err != nil {
		fmt.Println("无法读取:", err)
		return
	}

报错如下:

golang csv parse error on line 1, column 1: bare " in non-quoted-field

解决办法代码

由于再window下会有格式问题,添加两行代码可解决

	csvFile, _ := os.Open("file.csv")
	reader := csv.NewReader(csvFile)
	reader.Comma = ','  //添加
	reader.LazyQuotes = true  //添加
	records, err := reader.ReadAll()
	if err != nil {
		fmt.Println("无法读取:", err)
		return
	}

你可能感兴趣的:(golang,开发语言,后端)