GoogleWeatherWebサービスからXMLデータを読み取ろうとしています。応答にはスペイン語の文字が含まれています。問題は、これらの文字が正しく表示されないことです。すべてをUTF-8に変換しようとしましたが、それは役に立たないようです。コードを以下に示します
public static void main(String[] args) {
try {
URL url = new URL("http://www.google.com/ig/api?weather=Noja&hl=es");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(
con.getInputStream(), "UTF-8"));
String str = in.readLine();
//this does not work even
//String str = new String(in.readLine().getBytes("UTF-8"),"UTF-8");
System.out.println(str);
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
出力は以下のとおりです(投稿を制限内に保つためにトリミングされています)。「mi�」とs�bに注意してください
最大文字数制限を維持するためにトリミング
<day_of_week data="mi�"/><day_of_week data="s�b"/><low data="11"/><high data="16"/><icon data="/ig/images/weather/chance_of_rain.gif"/><condition data="Posibilidad de lluvia"/></forecast_conditions></weather></xml_api_reply>