Reputation: 801
I'm trying to grab some text from a Portuguese site that is encoded in ISO-8859-1 according to the meta tag. I'm using NodeJS and the request-promise package. What I get back, for example, is
Alg�s
I believe I need to convert that to ISO-8859-1 in NodeJS/Javascript. I have tried decodeURIComponent, encodeURIComponent, unescape and escape. None of those worked. Some of those even made things worse for the string. Anyone have any idea how to solve this?
Thanks in advance.
Upvotes: 4
Views: 816
Reputation: 21
If you are requesting the data via fetch
, you can try to convert the data into an arrayBuffer:
let result = [];
fetch('isoEncodedApi/data.json').then(response => {
response.arrayBuffer().then(arrayBuffer => {
const textDecoder = new TextDecoder('iso-8859-1');
const decodedResult = textDecoder.decode(arrayBuffer);
result = JSON.parse(decodedResult);
});
});
Upvotes: 1