質問編集履歴
1
調べたことを反映
title
CHANGED
File without changes
|
body
CHANGED
@@ -5,26 +5,11 @@
|
|
5
5
|
最終的にはgetWeather()のようなメソッドをつくり
|
6
6
|
使いたいです
|
7
7
|
|
8
|
-
|
9
|
-
###発生している問題・エラーメッセージ
|
10
|
-
|
8
|
+
```ここに言語を入力
|
11
|
-
```
|
12
|
-
|
13
|
-
|
14
|
-
public class gotenki {
|
15
|
-
Charset charset;
|
16
|
-
String Weather;
|
17
|
-
|
18
|
-
public String getWeather() {
|
19
|
-
return Weather;
|
20
|
-
}
|
21
|
-
|
22
|
-
public gotenki() {
|
23
|
-
this.charset = StandardCharsets.UTF_8;
|
24
|
-
}
|
25
|
-
|
9
|
+
public void tenki(String location, String area) throws MalformedURLException, IOException {
|
10
|
+
this.area = area;
|
26
|
-
URL url=new URL("http://weather.livedoor.com/forecast/webservice/json/v1?city="+location);
|
11
|
+
URL url = new URL("http://weather.livedoor.com/forecast/webservice/json/v1?city=" + location);
|
27
|
-
HttpURLConnection con = (HttpURLConnection)url.openConnection();
|
12
|
+
HttpURLConnection con = (HttpURLConnection) url.openConnection();
|
28
13
|
con.setRequestMethod("GET");
|
29
14
|
con.connect();
|
30
15
|
String json_st = "";
|
@@ -32,18 +17,25 @@
|
|
32
17
|
String line = "";
|
33
18
|
while ((line = reader.readLine()) != null) {
|
34
19
|
json_st += line;
|
20
|
+
}
|
35
|
-
|
21
|
+
System.out.println(json_st);
|
36
22
|
}
|
37
|
-
ObjectMapper ob=new ObjectMapper();
|
23
|
+
ObjectMapper ob = new ObjectMapper();
|
24
|
+
|
38
|
-
JsonNode json=ob.readTree(json_st);
|
25
|
+
JsonNode json = ob.readTree(json_st);
|
39
|
-
Weather=json.
|
26
|
+
Weather = json.get("forecasts").get("0").get(telop).textValue();
|
40
|
-
System.out.println(Weather);
|
41
|
-
|
42
|
-
|
27
|
+
}
|
28
|
+
System.out.println(ob);
|
43
29
|
}
|
44
|
-
```
|
30
|
+
```
|
31
|
+
###発生している問題・エラーメッセージ
|
32
|
+
nullと返される
|
33
|
+
```
|
45
34
|
|
46
35
|
|
36
|
+
|
37
|
+
|
38
|
+
|
47
39
|
###試したこと
|
48
40
|
jacksonの使い方を調べたがパースはどうするのかということを見つけられなかった
|
49
41
|
|