Google Weather API에서 날씨 정보를 읽으려고합니다.Google Weather API에서 반환 한 Umlauts가 제대로 표시되지 않습니다.
내 코드는 다음과 유사합니다
String googleWeatherUrl = "http://www.google.de/ig/api?weather=berlin&hl=de";
InputStream in = null;
String xmlString = "";
String line = "";
URL url = null;
try {
url = new URL(googleWeatherUrl);
in = url.openStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in, UTF_8));
while ((line = bufferedReader.readLine()) != null) {
xmlString += line;
}
} catch (MalformedURLException e) {
} catch (IOException e) {
}
DocumentBuilder builder = null;
Document doc = null;
try {
builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
InputSource source = new InputSource(new StringReader(xmlString));
doc = builder.parse(source);
} catch (ParserConfigurationException e) {}
catch (FactoryConfigurationError e) {}
catch (SAXException e) {} catch (IOException e) {}
은 기본적으로는 샤름처럼 작동하지만 반환 된 데이터가 움라우트가 포함 된 경우 (ö, ü는, ...) 다음 해당 문자가 제대로 표시되지 않습니다. 이클립스뿐만 아니라 브라우저 나 해당 소스 코드에서 사각형 (또는 비슷한 이상한 것)으로 표시됩니다.
실제로 변수 xmlString에 손상된 움라우트가 포함되어 있습니다.
아무도 아이디어가 있습니까?
감사와 안부, 폴 문자 인코딩의 마법의 세계에
당신은 그 문자 알려해야 길을 잃었다. 'xmlString'은 여전히 그들을 포함합니까? – home
좋은 전화입니다. 나는 그 질문을 편집했다. xmlString은 이미 손상되었습니다 ... – Paul
서버의 응답은 UTF-8이 아닌 ISO-8859-1 (훌륭한 직업, Google)입니다. 그것이 틀린 이유입니다. 수동으로 인코딩을 설정하지 않아도된다고 생각합니다. 그렇지 않으면 [HttpURLConnection] (http://docs.oracle.com/javase/1.4.2/docs/api/java/net/HttpURLConnection.html)을 사용하여 Content-Type 헤더를 가져올 수 밖에 없습니다. 인코딩을 분석하고 그에 따라 설정하십시오. 나는 Sun의 사람들이 정말로 생각 해보길 바란다. –