Skip to content

Instantly share code, notes, and snippets.

@silverwolfceh
Created February 15, 2019 01:23
Show Gist options
  • Save silverwolfceh/02a3b602e8befa52065d2035a8471270 to your computer and use it in GitHub Desktop.
Save silverwolfceh/02a3b602e8befa52065d2035a8471270 to your computer and use it in GitHub Desktop.
UTF8 Json parse javascript demo
function en2vi_trans(word)
{
var k = "trnsl.1.1.20190214T041113Z.bc4d15cca572abd8.xxxxxxxxxxxxxxxxxxxxxxxxxxxx"; //YANDEX API KEY, FREE
var url = "https://translate.yandex.net/api/v1.5/tr.json/translate?key=" + k + "&lang=en-vi&text=" + word;
return $.get(url, function(data) {
console.log(data);
info = JSON && JSON.parse(JSON.stringify(data)) || $.parseJSON(JSON.stringify(data));
if(info.code == 200)
{
var t = "Meaning of: " + word+ " is " + info.text[0];
alert(t);
return info.text[0];
}
else
return "Unavailable";
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment