質問編集履歴

3

マークアップにしたかった

2022/07/26 00:38

投稿

YUTA
YUTA

スコア1

test CHANGED
File without changes
test CHANGED
@@ -110,7 +110,7 @@
110
110
 
111
111
  ご回答宜しくお願い致します。
112
112
 
113
- 修正後
113
+ ### 修正後
114
114
  ```ここに言語を入力
115
115
  using System.Collections;
116
116
  using System.Collections.Generic;

2

修正しました。

2022/07/26 00:38

投稿

YUTA
YUTA

スコア1

test CHANGED
File without changes
test CHANGED
@@ -110,3 +110,81 @@
110
110
 
111
111
  ご回答宜しくお願い致します。
112
112
 
113
+ 修正後
114
+ ```ここに言語を入力
115
+ using System.Collections;
116
+ using System.Collections.Generic;
117
+ using UnityEngine;
118
+ using UnityEngine.Networking;
119
+ using UnityEngine.UI;
120
+
121
+
122
+ public class WeatherController : MonoBehaviour
123
+ {
124
+ static string access_url = "https://weather.tsukumijima.net/api/forecast?city=400040";
125
+ // Start is called before the first frame update
126
+ void Start()
127
+ {
128
+ //StartCoroutine("ApiRequest");
129
+ StartCoroutine(ApiRequest());
130
+ }
131
+
132
+ // Update is called once per frame
133
+ void Update()
134
+ {
135
+
136
+ }
137
+ static IEnumerator ApiRequest()//非同期通信 IEnumerator
138
+ {
139
+ UnityWebRequest request = UnityWebRequest.Get(access_url);
140
+ request.SetRequestHeader("Content-Type", "application/json");
141
+
142
+ yield return request.SendWebRequest();
143
+
144
+ if (request.isHttpError)
145
+ {
146
+ // レスポンスコードを見て処理
147
+ Debug.Log($"[Error]Response Code : {request.responseCode}");
148
+ }
149
+ else if (request.isNetworkError)
150
+ {
151
+ // エラーメッセージを見て処理
152
+ Debug.Log($"[Error]Message : {request.error}");
153
+ }
154
+ else
155
+ {
156
+ // 成功したときの処理
157
+ Weather response = JsonUtility.FromJson<Weather>(request.downloadHandler.text);
158
+
159
+ //全文は表示されるけど
160
+ Debug.Log(request.downloadHandler.text);
161
+ //天気を表示したい
162
+ //Debug.Log("weather: " + response.forecasts[0].detail.weather);
163
+ Debug.Log("weather: " + response.weather);
164
+
165
+ yield return null;
166
+ }
167
+
168
+ }
169
+
170
+
171
+ public class Forecasts
172
+ {
173
+ public IList <string> forecasts { get; set; }
174
+
175
+ }
176
+ public class Detail:Forecasts
177
+ {
178
+ public string detail { get; set; }
179
+ }
180
+ public class Weather:Detail
181
+ {
182
+ public string weather { get; set; }
183
+ }
184
+
185
+
186
+
187
+ }
188
+
189
+ ```
190
+

1

テンプレートの形式では見にくかったのでソースコードを前に持ってきた

2022/07/26 00:07

投稿

YUTA
YUTA

スコア1

test CHANGED
File without changes
test CHANGED
@@ -6,25 +6,6 @@
6
6
  ### 実現したいこと
7
7
  [https://weather.tsukumijima.net/api/forecast?city=400040](url)
8
8
  このjsonのうち天気(response.forecasts[0].detail.weather)を表示したいです。
9
-
10
- ### 発生している問題・エラーメッセージ
11
-
12
- ```ここに言語を入力
13
- //全文は表示されるけど
14
- Debug.Log(request.downloadHandler.text);
15
- ```
16
- ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-07-26/47eb5fcc-4c67-4a7e-ab45-4ecb970dc9a5.png)
17
- ```ここに言語を入力
18
- //天気が表示されない
19
- //ひとまずforecastsを表示してみる
20
- Debug.Log("weather: " + response.forecasts);
21
- ```
22
- ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-07-26/1def06b8-05fe-41b2-8432-d6736d1ab6e2.png)
23
- ```ここに言語を入力
24
- //これだとエラー
25
- Debug.Log("weather: " + response.forecasts[0].detail.weather);
26
- ```
27
- ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-07-26/331490fc-051c-490f-847d-11bfb003674b.png)
28
9
 
29
10
  ### 該当のソースコード
30
11
 
@@ -96,6 +77,26 @@
96
77
 
97
78
  ```
98
79
 
80
+ ### 発生している問題・エラーメッセージ
81
+
82
+ ```ここに言語を入力
83
+ //全文は表示されるけど
84
+ Debug.Log(request.downloadHandler.text);
85
+ ```
86
+ ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-07-26/47eb5fcc-4c67-4a7e-ab45-4ecb970dc9a5.png)
87
+ ```ここに言語を入力
88
+ //天気が表示されない
89
+ //ひとまずforecastsを表示してみる
90
+ Debug.Log("weather: " + response.forecasts);
91
+ ```
92
+ ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-07-26/1def06b8-05fe-41b2-8432-d6736d1ab6e2.png)
93
+ ```ここに言語を入力
94
+ //これだとエラー
95
+ Debug.Log("weather: " + response.forecasts[0].detail.weather);
96
+ ```
97
+ ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-07-26/331490fc-051c-490f-847d-11bfb003674b.png)
98
+
99
+
99
100
  ### 試したこと
100
101
 
101
102
  当該jsonに対して他webサイトを見様見真似で様々なアプローチをしたが取り出せなかった。