質問編集履歴

1

調べたことを反映

2017/10/28 10:39

投稿

musicexbp
musicexbp

スコア13

test CHANGED
File without changes
test CHANGED
@@ -12,45 +12,15 @@
12
12
 
13
13
 
14
14
 
15
+ ```ここに言語を入力
15
16
 
17
+ public void tenki(String location, String area) throws MalformedURLException, IOException {
16
18
 
17
- ###発生している問題・エラーメッセージ
19
+ this.area = area;
18
20
 
19
- nullと返される
21
+ URL url = new URL("http://weather.livedoor.com/forecast/webservice/json/v1?city=" + location);
20
22
 
21
- ```
22
-
23
-
24
-
25
-
26
-
27
- public class gotenki {
28
-
29
- Charset charset;
30
-
31
- String Weather;
32
-
33
-
34
-
35
- public String getWeather() {
36
-
37
- return Weather;
38
-
39
- }
40
-
41
-
42
-
43
- public gotenki() {
44
-
45
- this.charset = StandardCharsets.UTF_8;
46
-
47
- }
48
-
49
- public void tenki(String location) throws MalformedURLException, IOException{
50
-
51
- URL url=new URL("http://weather.livedoor.com/forecast/webservice/json/v1?city="+location);//locationはすでに呼び出しクラスから指定済み 例にのっている福岡のIDは400040
52
-
53
- HttpURLConnection con = (HttpURLConnection)url.openConnection();
23
+ HttpURLConnection con = (HttpURLConnection) url.openConnection();
54
24
 
55
25
  con.setRequestMethod("GET");
56
26
 
@@ -66,25 +36,39 @@
66
36
 
67
37
  json_st += line;
68
38
 
39
+ }
40
+
69
- } System.out.println(json_st);
41
+ System.out.println(json_st);
70
42
 
71
43
  }
72
44
 
73
- ObjectMapper ob=new ObjectMapper();
45
+ ObjectMapper ob = new ObjectMapper();
74
46
 
75
- JsonNode json=ob.readTree(json_st);
76
47
 
77
- Weather=json.path("forecasts").path("date").textValue();
78
48
 
79
- System.out.println(Weather);
49
+ JsonNode json = ob.readTree(json_st);
80
50
 
81
-
51
+ Weather = json.get("forecasts").get("0").get(telop).textValue();
82
52
 
83
- }
53
+ }
54
+
55
+ System.out.println(ob);
84
56
 
85
57
  }
86
58
 
87
- ```java
59
+ ```
60
+
61
+ ###発生している問題・エラーメッセージ
62
+
63
+ nullと返される
64
+
65
+ ```
66
+
67
+
68
+
69
+
70
+
71
+
88
72
 
89
73
 
90
74