Winjs, error reading file with FileIO.readTextAsync
-
21-12-2019 - |
Вопрос
I am reading a .json file from disk using Windows.Storage.FileIO.readTextAsync
.
All is fine until I put some non english letters in the file, like Æ Å Ø
The error I get is (rough translation from Danish language): WinRT: No mapping for the Unicode character exists in the target multi-byte code page.
any idea how to read those chars in WinJs?
Решение
I found the problem.
when I created the file manually with notepad I set it to type ANSII instead of utf8. I reopened the file -> save as and the changed the type and overwrote it.
Другие советы
You may be able to solve this by changing the encoding from the default (Utf8
) to Utf16
. The readTextAsync
method accepts a second parameter which is a UnicodeEncoding flag:
Windows.Storage.FileIO.readTextAsync(
file,
Windows.Storage.Streams.UnicodeEncoding.utf16LE
).done( ... );
Or if you need to, you can use utf16BE
flag (see link above).