Skip to main content
Participant
January 21, 2025
Answered

Invalid characters used in text downloaded from external api

  • January 21, 2025
  • 1 reply
  • 504 views

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?

Correct answer Arie Stavchansky

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

1 reply

Legend
January 21, 2025

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.

vi_2372Author
Participant
January 21, 2025

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