Android 从文本解析时的未知字符

Android 从文本解析时的未知字符,android,Android,我正在从网站上读一行文字。下面是我读到的例子: 11:28;26.02.12;6.7°C;6.7°C;67;0.7m/s; 6:45;17:40; Warm ;84;0.9;0.0;; 一旦我读到字符串而不是6.7°C,我得到6.7°C�看起来这个网站不是UTF-8编码。我应该如何解决这个问题,我将用℉代替� ? 有没有可能在阅读时解决这个问题,或者我可以在进行字符串拆分时解决这个问题 以下是我目前用于从网站阅读的方法: public static String getContentFromU

我正在从网站上读一行文字。下面是我读到的例子:

11:28;26.02.12;6.7°C;6.7°C;67;0.7m/s; 6:45;17:40; Warm ;84;0.9;0.0;;
一旦我读到字符串而不是6.7°C,我得到6.7°C�看起来这个网站不是UTF-8编码。我应该如何解决这个问题,我将用℉代替� ? 有没有可能在阅读时解决这个问题,或者我可以在进行字符串拆分时解决这个问题

以下是我目前用于从网站阅读的方法:

public static String getContentFromUrl(String url) throws ClientProtocolException, IOException {

    HttpClient httpClient = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(url);
    HttpResponse response;

    response = httpClient.execute(httpGet);
    HttpEntity entity = response.getEntity();

    if(entity != null) {

        InputStream inStream = entity.getContent();

        String result = Weather.convertStreamToString(inStream);
        inStream.close();

        return result;
    }

    return null;

}

private static String convertStreamToString(InputStream is) {
    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
    StringBuilder sb = new StringBuilder();

    String line = null;

    try {
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            is.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return sb.toString();
}

服务器使用什么编码?你可以试试:

sb.append((new String(line, "UTF-8")) + "\n");


嗯,我应该在构造函数中声明这个新字符串?您只需将其中的一行放入while循环中。
sb.append((new String(line, "iso-8859-1")) + "\n");