Skip to main content
Participant
Jan 21, 2025 3:01 PM UTC
Answered

Invalid characters used in text downloaded from external api

Hi

 

I have script, which downloads texts from external api url and fill this texts into project TextLayer/TextDocument components.

I have problem with some glyphs, that are not displyed correctly

for example string from api (content utf8) is

 Rázová vlna by DRÉN

is displayed in TextDocument as

  R√°zov√° vlna by DR√âN

 

part of code is simple:

 

var textProp = layer.property("Source Text");
var textDoc = textProp.value;
textDoc.text = content.value;  // <--- here is content downloaded from api
textProp.setValue(textDoc);

 

 

How can I fix this?

When I write characters manually all is OK.

Data from script are valid characters.

Have you some hints for me?

Arie StavchanskyCorrect answer
Legend
Jan 21, 2025 3:44 PM UTC

Also, to add to my answer: in your script, you may want to also try setting the appEncoding before executing the system.callSystem() method.

 

I've tried this for a number of things, but it invariably causes issues with various languages of AE, so if you are building a product that will be installed in many systems, it can wreak havoc:

 

https://extendscript.docsforadobe.dev/extendscript-tools-features/dollar-object.html#appencoding

7 replies

Legend
Jan 21, 2025 3:24 PM UTC

Where is the data stored for the `content` variable?  Is the data you are retrieving from the API saved to a file?  Or, are you using ExtendScripts sockets implementation (which is quite poor implementation of sockets).  If the data is being saved to a file buffer, that file must be character encoded to UTF-8.  Otherwise, this kind of thing can happen.

Translate
vi_2372Author
Participant
Jan 21, 2025 3:28 PM UTC

I am downloading it manually via system.callSystem api

var data = JSON.parse(system.callSystem('curl -s "' + url + '"'));

and using JSON implementation from json2.js 

Translate