GoogleWeatherAPIから天気情報を読み込もうとしています。
私のコードは次のようになります。
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) {}
基本的にはチャームのように機能しますが、返されるデータにウムラウト(ö、ü、ä、...)が含まれている場合、それらの文字は正しく表示されません。Eclipse、ブラウザ、または対応するソースコードでは、長方形(または同様の奇妙なもの)として表示されます。
実際には、変数xmlStringには破損したウムラウトが含まれています。
誰かがそれについて考えを持っていますか?
よろしくお願いします、ポール