【问题标题】:Android not able to recognize different language FontsAndroid 无法识别不同的语言字体
【发布时间】:2016-08-21 16:21:48
【问题描述】:

制作了一个应用程序来将不同的单词翻译成不同的语言 使用 Yandex 转换器在浏览器上获得正确的结果
转换亲吻
作为 JSON 对象的结果是 {"code":200,"lang":"en-hi","text":["चुम्बन"]} //proper
但是在应用程序上获得结果时 结果 {"code":200,"lang":"en-hi","text":["à¤à¥à¤®à¥à¤¬à¤¨"]}

 JSONParser jParser = new JSONParser();
  // get json string from url
 JSONObject json = jParser.getJSONFromUrl(yourJsonStringUrl);

geJSONFromUrl 函数

public JSONObject getJSONFromUrl(String urlSource) {
    //make HTTP request
    try {
        URL url = new URL(urlSource);
        HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
        urlConnection.setDoOutput(true);
        urlConnection.setChunkedStreamingMode(0);
        inputStream = new BufferedInputStream(urlConnection.getInputStream());
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    //Read JSON data from inputStream
    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"), 8);
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
        inputStream.close();
        json = sb.toString();
    } catch (Exception e) {
        Log.e(TAG, "Error converting result " + e.toString());
    }

    // try parse the string to a JSON object
    try {
        jObj = new JSONObject(json);
    } catch (JSONException e) {
        Log.e(TAG, "Error parsing data " + e.toString());
    }

    return jObj;// return JSON String
}

}

有什么方法可以得到正确的结果吗?
请帮助
问候

【问题讨论】:

  • 也许您使用了错误的文本编码? getJSONFromUrl 函数长什么样子?
  • 添加到问题中
  • 能否请您提供服务器端代码。我认为这与编码有关。在 PHP(例如)中,您应该使用类似 link.
  • @R.Mazarei 不需要 php 代码从此链接获取结果translate.yandex.net/api/v1.5/tr.json/…
  • 在代码中用作https://translate.yandex.net/api/v1.5/tr.json/translate?key=trnsl.1.1.20140720T191145Z.05605441c6ee16dc.eaaf6c6c8690cb5fb094cea2bfec4f787af6170c&lang=en-hi&text="+ TextUtils.htmlEncode(MainActivity.toTranslate)

标签: java android translation yandex


【解决方案1】:

变了

 BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"), 8);

 BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多