Javascript FileReader readAsText function not unde

2019-05-20 05:03发布

问题:

I have tried searching this a lot and nothing helped me. I have an import from csv feature and javascript code reads the csv content line by line. The characters ä,ö etc are just not recognized. FileReader readAsText has default encoding utf-8 but in this case it is not for some reason working. Here is my code.

            reader = new FileReader()
            reader.onload = (e) =>
              result = e.target.result
              console.log result
              # file content
              fileContent = result.split("\r")

            reader.readAsText(e.target.files.item(0))

I have tried defining encoding like below and whatever I put there couldn't help me.

encoding = "UTF-8"
reader.readAsText(e.target.files.item(0), encoding)

回答1:

I got this to work by using ISO Latin 4 encoding.

reader.readAsText(e.target.files.item(0), 'ISO-8859-4');

That should work for you but remember to use this particular encoding just for some scandinavian characters.