###前提・実現したいこと
livedoorのJSON天気APIを使い,"今日"の天気と最高温度、最低温度を取り出したい
jacksonを用いればjsonを読み込むことができるとありますが
使いかたがよくわかりません
最終的にはgetWeather()のようなメソッドをつくり
使いたいです
public void tenki(String location, String area) throws MalformedURLException, IOException { this.area = area; URL url = new URL("http://weather.livedoor.com/forecast/webservice/json/v1?city=" + location); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("GET"); con.connect(); String json_st = ""; try (BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream()))) { String line = ""; while ((line = reader.readLine()) != null) { json_st += line; } System.out.println(json_st); } ObjectMapper ob = new ObjectMapper(); JsonNode json = ob.readTree(json_st); Weather = json.get("forecasts").get("0").get(telop).textValue(); } System.out.println(ob); }
###発生している問題・エラーメッセージ
nullと返される
###試したこと jacksonの使い方を調べたがパースはどうするのかということを見つけられなかった ###補足情報(言語/FW/ツール等のバージョンなど) java1.8
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/10/28 10:36
2017/10/30 00:50