gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:36:17 24 4
gpt4 key购买 nike

我正在尝试下载包含斯洛文尼亚字符的 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");

希望对您有所帮助!

关于android - 如何下载包含斯洛文尼亚特殊字符的字符串文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47904580/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com