android – 如何下载包含斯洛文尼亚特殊字符的字符串文件

前端之家收集整理的这篇文章主要介绍了android – 如何下载包含斯洛文尼亚特殊字符的字符串文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试下载包含斯洛文尼亚字符的json文件,在下载json文件作为字符串时,我将获得json数据中指定的特殊字符
"send_mail": "Po�lji elektronsko sporocilo.","str_comments_likes": "Komentarji,v�ecki in mejniki",

我正在使用的代码

URL url = new URL(f_url[0]);
URLConnection conection = url.openConnection();
conection.connect();
try {
    InputStream input1 = new BufferedInputStream(url.openStream(),300);
    String myData = "";
    BufferedReader r = new BufferedReader(new InputStreamReader(input1));
    StringBuilder totalValue = new StringBuilder();
    String line;
    while ((line = r.readLine()) != null) {
        totalValue.append(line).append('\n');
    }
    input1.close();
    String value = totalValue.toString();
    Log.v("To Check Problem from http paramers",value);
} catch (Exception e) {
    Log.v("Exception Character Isssue","" + e.getMessage());
}

我想知道如何正确下载字符.

解决方法

您需要将字符串字节编码为UTF-8.请检查以下代码
String slovenianJSON = new String(value.getBytes([Original Code]),"utf-8");
JSONObject newJSON = new JSONObject(reconstitutedJSONString);
String javaStringValue = newJSON.getString("content");

我希望它会对你有所帮助!

原文链接:https://www.f2er.com/android/309370.html

猜你在找的Android相关文章