android - 如何在android中打印特殊字符

标签 android

这是我的网络服务响应..

Testperson-se,Approved,Stårgatan 1,12345,Ankeborg,SE

现在在 Stårgatan 的这个字符串中有一个带点的特殊字符,当我打印此响应时它给我问号字符串,例如 ..

Testperson-se,Approved,St?rgatan 1,12345,Ankeborg,SE

我使用以下代码。

try {
            URL url = new URL(
                    "http://www.ecodor.se/administrator/components/com_ivmstore/ivmwebservices/getaddress.php?pNumber=410321-9202"
                            );// 

            InputSource is = new InputSource(url.openStream());

            StringBuffer res = new StringBuffer();

            res.append(convertStreamToString(is.getByteStream()));

            line = res.toString();

            Log.i("==> responce", line);

            //

        } catch (Exception e) {

        }

public String convertStreamToString(InputStream is) throws IOException {
    /*
     * To convert the InputStream to String we use the
     * BufferedReader.readLine() method. We iterate until the BufferedReader
     * return null which means there's no more data to read. Each line will
     * appended to a StringBuilder and returned as String.
     */
    if (is != null) {
        StringBuilder sb = new StringBuilder();
        String line;

        try {
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(is, "UTF-8"));
            while ((line = reader.readLine()) != null) {
                sb.append(line).append("\n");
            }
        } finally {
            is.close();
        }
        return sb.toString();
    } else {
        return "";
    }
}

如何打印这个特殊字符?

最佳答案

您可能希望使用 InputSource#getEncoding 返回的编码

Get the character encoding for a byte stream or URI. This value will be ignored when the application provides a character stream.

关于android - 如何在android中打印特殊字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12602598/

相关文章:

android - 如何在android中选择PDF文件

android - 无法启动 'org.qtproject.example.testapp'

android - Dart :UI not found while trying to run . 飞镖文件

android - Glide 占位符矢量可绘制资源未找到异常

android - 覆盖在 css 文件中声明的 android 中的字体大小和背景颜色

android - 我的 ScrollView 根本不起作用

android - Intent 与 ACTION_VIEW 和 uri 指向 EXTRA_STREAM 中的 ParcelFileDescriptor

android - 如何在 Android 中正确使用 React Native 中的仅限 iOS 的组件而不会出错

android - 无法解析符号 'NavigationView'

javascript - 未捕获的类型错误 : Cannot read property 'tagName' of null