2

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

Testperson-se,已批准,Stårgatan 1,12345,Ankeborg,SE

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

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 "";
    }
}

如何打印这个特殊字符?

4

2 回答 2

1

您可能想要使用InputSource#getEncoding返回的编码

获取字节流或 URI 的字符编码。当应用程序提供字符流时,该值将被忽略。

于 2012-09-26T13:20:01.167 回答
0

我通过使用以下解决它。

BufferedReader reader = new BufferedReader(
                    new InputStreamReader(is, "ISO-8859-1"));

感谢所有给我想法的人。

于 2012-09-27T04:45:49.730 回答