Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static String translate123(String lang, String input) throws IOException {
- String urlStr = "https://dictionary.yandex.net/api/v1/dicservice.json/lookup?key=dict.1.1.20170324T082045Z.5089076809ee28a9.ffa2a8f71e0c7c4a629cfa04aa38975a721fdaa6&";
- URL urlObj = new URL(urlStr);
- HttpsURLConnection connection = (HttpsURLConnection)urlObj.openConnection();
- connection.setRequestMethod("POST");
- connection.setDoOutput(true);
- DataOutputStream dataOutputStream = new DataOutputStream(connection.getOutputStream());
- dataOutputStream.writeBytes("lang="+ lang + "&text=" + URLEncoder.encode(input, "UTF-8"));
- InputStream response = connection.getInputStream();
- String json = null;
- Scanner scn = new Scanner(response);
- while(scn.hasNextLine()){
- json = scn.nextLine();
- }
- int start = json.indexOf("[");
- int end = json.indexOf("]");
- String translated = json;
- i++;
- //вот это вот заморочка для русского. Иначе эту шляпу делать не надо
- //хотя она не мешает и с ангельским
- byte ptext[] = translated.getBytes();
- String encodedStr = new String(ptext, "UTF-8");
- return encodedStr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement