質問
How to Decode CURL Response Correctly ?
Using:
decodeURIComponent(escape(datas[i].display_name))
I have an error and escape() is deprecated, I think the problem is with the Î character \u017D

And using a decode() function
function decode(s) {
for (var a, b, i = -1, l = (s = s.split("")).length, o = String.fromCharCode, c = "charCodeAt"; ++i < l;
((a = s[i][c](0)) & 0x80) &&
(s[i] = (a & 0xfc) == 0xc0 && ((b = s[i + 1][c](0)) & 0xc0) == 0x80 ?
o(((a & 0x03) << 6) + (b & 0x3f)) : o(128), s[++i] = "")
);
return s.join("");
}
it works better but I still have a problem with some characters

nominatim.jsx
(function(thisObj) {
function decode(s) {
for (var a, b, i = -1, l = (s = s.split("")).length, o = String.fromCharCode, c = "charCodeAt"; ++i < l;
((a = s[i][c](0)) & 0x80) &&
(s[i] = (a & 0xfc) == 0xc0 && ((b = s[i + 1][c](0)) & 0xc0) == 0x80 ?
o(((a & 0x03) << 6) + (b & 0x3f)) : o(128), s[++i] = "")
);
return s.join("");
}
buildUI(thisObj);
function buildUI(thisObj) {
var proj = app.project;
var thisComp = proj.activeItem;
var palette = (thisObj instanceof Panel) ? thisObj : new Window("palette", "Nominatim", undefined, {
resizeable: true
})
palette.alignChildren = ["left", "center"];
palette.margins = 5;
palette.spacing = 2;
var edittext1 = palette.add('edittext {properties: {name: "edittext1"}}');
edittext1.preferredSize.width = 640;
var listbox1 = palette.add("listbox", undefined, undefined, {
name: "listbox1",
items: []
});
listbox1.preferredSize.width = 640;
if (palette instanceof Window) {
palette.center();
palette.show()
} else {
palette.layout.layout(true);
palette.layout.resize()
}
edittext1.addEventListener("keydown", function(e) {
palette.remove(listbox1);
var arr = [];
if (e.keyName == 'Enter') {
var url = "https://nominatim.openstreetmap.org/search?q=" + encodeURI(this.text) + "&format=json&polygon=1&addressdetails=1";
var datas = JSON.parse(system.callSystem("curl -s \"Accept: application/json\" \"" + url + "\""));
for (var i = 0; i < datas.length; i++) {
//arr.push(decodeURIComponent(escape(datas[i].display_name)))
arr.push(decode(datas[i].display_name))
}
listbox1 = palette.add("listbox", undefined, undefined, {
name: "listbox1",
items: arr
});
listbox1.onChange = function() {
var proj = app.project;
var thisComp = proj.activeItem;
if (thisComp.numLayers && thisComp.layer(1) instanceof TextLayer) {
thisComp.layer(1).text.sourceText.setValue(this.selection.text);
} else {
thisComp.layers.addText(this.selection.text)
}
}
} else {
listbox1 = palette.add("listbox", undefined, undefined, {
name: "listbox1",
items: []
});
}
listbox1.preferredSize.width = 640;
palette.layout.layout(true);
});
}
})(this);
