Ruby/Rails CSV parsing, invalid byte sequence in UTF-8

前端 未结 7 1728
别跟我提以往
别跟我提以往 2020-12-24 01:02

I am trying to parse a CSV file generated from an Excel spreadsheet.

Here is my code

require \'csv\'
file = File.open(\"input_file\")
csv = CSV.parse         


        
7条回答
  •  暖寄归人
    2020-12-24 01:35

    You need to tell Ruby that the file is in ISO-8859-1. Change your file open line to this:

    file=File.open("input_file", "r:ISO-8859-1")
    

    The second argument tells Ruby to open read only with the encoding ISO-8859-1.

提交回复
热议问题