質問編集履歴
1
自分の書いたコードの追加
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
unity(C#)でjson取得したデーターの
|
1
|
+
unity(C#)でjson取得したデーター[ { { 個々 } } ] のデーターを取得したい
|
body
CHANGED
@@ -26,4 +26,256 @@
|
|
26
26
|
],
|
27
27
|
}
|
28
28
|
```
|
29
|
-
この中のtemperatureの中のminの中のfahrenheitが取得したいのですがどうしても取得できませんでした。やり方を知っていたら教えて下さい、よろしくお願いします。
|
29
|
+
この中のtemperatureの中のminの中のfahrenheitが取得したいのですがどうしても取得できませんでした。やり方を知っていたら教えて下さい、よろしくお願いします。
|
30
|
+
|
31
|
+
|
32
|
+
追記
|
33
|
+
自分が書いていたコードです
|
34
|
+
```c#
|
35
|
+
using System;
|
36
|
+
using System.Collections;
|
37
|
+
using System.Collections.Generic;
|
38
|
+
using System.Text;
|
39
|
+
using UnityEngine;
|
40
|
+
using UnityEngine.Events;
|
41
|
+
using UnityEngine.UI;
|
42
|
+
using MiniJSON;
|
43
|
+
using JsonData;
|
44
|
+
|
45
|
+
public class WeatherAPI_test1 : MonoBehaviour
|
46
|
+
{
|
47
|
+
|
48
|
+
static public string url = "http://weather.livedoor.com/forecast/webservice/json/v1?city=400040";//天気URL
|
49
|
+
|
50
|
+
string advis;
|
51
|
+
string image;
|
52
|
+
|
53
|
+
void Start()
|
54
|
+
{
|
55
|
+
|
56
|
+
StartCoroutine("connectdata");
|
57
|
+
}
|
58
|
+
|
59
|
+
private IEnumerator connectdata()
|
60
|
+
{
|
61
|
+
WWW www = new WWW(url);
|
62
|
+
yield return www;
|
63
|
+
if (!string.IsNullOrEmpty(www.error))
|
64
|
+
{
|
65
|
+
|
66
|
+
print("Error downloading: " + www.error);
|
67
|
+
|
68
|
+
}
|
69
|
+
else
|
70
|
+
{
|
71
|
+
|
72
|
+
string jsonText = www.text;//受け取ったデーターをjsonTextにIN
|
73
|
+
|
74
|
+
JsonDataClass jsonDataClass;
|
75
|
+
JsonDataClas_image jsonDataClas_image;
|
76
|
+
|
77
|
+
jsonDataClass = JsonUtility.FromJson<JsonDataClass>(jsonText);
|
78
|
+
|
79
|
+
|
80
|
+
Debug.Log(jsonText);
|
81
|
+
|
82
|
+
var json = jsonText;
|
83
|
+
//(1階層目)
|
84
|
+
var jsonData = MiniJSON.Json.Deserialize(json) as Dictionary<string, object>;//全体の並列取得
|
85
|
+
//(2階層目)
|
86
|
+
var description = jsonData["description"] as Dictionary<string, object>;//天気概況文の配列
|
87
|
+
var forecasts = (IList)jsonData["forecasts"];//府県天気予報の予報日毎の配列
|
88
|
+
var pinpointLocations = (IList)jsonData["pinpointLocations"];//ピンポイント予報の発表地点の配列
|
89
|
+
var location = jsonData["location"] as Dictionary<string, object>;//予報を発表した地域を定義
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
//(3階層目)
|
96
|
+
var forecasts_0 = (IDictionary)forecasts[0];
|
97
|
+
var forecasts_1 = (IDictionary)forecasts[1];
|
98
|
+
var forecasts_2 = (IDictionary)forecasts[2];
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
var pinpointLocations_0 = (IDictionary)pinpointLocations[0];
|
103
|
+
var pinpointLocations_1 = (IDictionary)pinpointLocations[1];
|
104
|
+
var pinpointLocations_2 = (IDictionary)pinpointLocations[2];
|
105
|
+
var pinpointLocations_3 = (IDictionary)pinpointLocations[3];
|
106
|
+
var pinpointLocations_4 = (IDictionary)pinpointLocations[4];
|
107
|
+
var pinpointLocations_5 = (IDictionary)pinpointLocations[5];
|
108
|
+
var pinpointLocations_6 = (IDictionary)pinpointLocations[6];
|
109
|
+
var pinpointLocations_7 = (IDictionary)pinpointLocations[7];
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
Debug.Log(jsonDataClass.title);
|
114
|
+
OUTPutUI_script.title = jsonDataClass.title;
|
115
|
+
|
116
|
+
advis = (string)description["text"];
|
117
|
+
|
118
|
+
OUTPutUI_script.advice = advis.Replace("\n", "");
|
119
|
+
|
120
|
+
OUTPutUI_script.today_dateLabel = (string)forecasts_0["dateLabel"];
|
121
|
+
OUTPutUI_script.today_weather = (string)forecasts_0["telop"];
|
122
|
+
OUTPutUI_script.today_date = (string)forecasts_0["date"];
|
123
|
+
|
124
|
+
OUTPutUI_script.tomorrow_dateLabel = (string)forecasts_1["dateLabel"];
|
125
|
+
OUTPutUI_script.tomorrow_weather = (string)forecasts_1["telop"];
|
126
|
+
OUTPutUI_script.tomorrow_date = (string)forecasts_1["date"];
|
127
|
+
|
128
|
+
OUTPutUI_script.afterTomorrow_dateLabel = (string)forecasts_2["dateLabel"];
|
129
|
+
OUTPutUI_script.afterTomorrow_weather = (string)forecasts_2["telop"];
|
130
|
+
OUTPutUI_script.afterTomorrow_date = (string)forecasts_2["date"];
|
131
|
+
|
132
|
+
Debug.Log((string)forecasts_0["dateLabel"]);//予報日(今日、明日、明後日のいずれか)
|
133
|
+
Debug.Log((string)forecasts_0["telop"]);//天気
|
134
|
+
Debug.Log((string)forecasts_0["date"]);//予報日
|
135
|
+
|
136
|
+
Debug.Log((string)forecasts_1["dateLabel"]);//予報日(今日、明日、明後日のいずれか)
|
137
|
+
Debug.Log((string)forecasts_1["telop"]);//天気
|
138
|
+
Debug.Log((string)forecasts_1["date"]);//予報日
|
139
|
+
|
140
|
+
|
141
|
+
|
142
|
+
// Debug.Log((string)forecasts_2["dateLabel"]);//予報日(今日、明日、明後日のいずれか)
|
143
|
+
// Debug.Log((string)forecasts_2["telop"]);//天気
|
144
|
+
// Debug.Log((string)forecasts_2["date"]);//予報日
|
145
|
+
|
146
|
+
Debug.Log((string)pinpointLocations_0["link"]);//リンク
|
147
|
+
Debug.Log((string)pinpointLocations_0["name"]);//リンク
|
148
|
+
Debug.Log((string)pinpointLocations_1["link"]);//リンク
|
149
|
+
Debug.Log((string)pinpointLocations_1["name"]);//リンク
|
150
|
+
|
151
|
+
Debug.Log((string)description["text"]);//天気概況本文
|
152
|
+
Debug.Log((string)description["publicTime"]);//天気概況文の発表時刻
|
153
|
+
|
154
|
+
|
155
|
+
|
156
|
+
// Debug.Log((double)location["city"]);//都市
|
157
|
+
Debug.Log((string)location["area"]);//地方名(例・九州地方)
|
158
|
+
Debug.Log((string)location["prefecture"]);//都道府県名(例・福岡県)
|
159
|
+
Debug.Log((string)location["city"]);//1次細分区名(例・八幡)
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
// Debug.Log((double)main["temp_max"]);//最高気温
|
164
|
+
// Debug.Log((double)coord["lon"]);//経度
|
165
|
+
// Debug.Log((double)main["pressure"]);//気圧
|
166
|
+
// Debug.Log((long)main["humidity"]);//湿度
|
167
|
+
// Debug.Log((double)wind["speed"]);//風速
|
168
|
+
// Debug.Log((string)jsonData["name"]);//都市名
|
169
|
+
// Debug.Log((string)sys["country"]);//国名
|
170
|
+
// Debug.Log((long)sys["sunrise"]);//日の出時間
|
171
|
+
// Debug.Log((long)sys["sunset"]);//日没時間
|
172
|
+
|
173
|
+
|
174
|
+
}
|
175
|
+
}
|
176
|
+
}
|
177
|
+
namespace JsonData
|
178
|
+
{
|
179
|
+
public class JsonDataClass
|
180
|
+
{
|
181
|
+
|
182
|
+
public string publicTime;//予報の発表日時
|
183
|
+
|
184
|
+
public string title;//タイトル・見出し
|
185
|
+
|
186
|
+
public string link;
|
187
|
+
|
188
|
+
public string telop;
|
189
|
+
|
190
|
+
}
|
191
|
+
public class JsonDataClas_image
|
192
|
+
{
|
193
|
+
public string image;
|
194
|
+
}
|
195
|
+
}
|
196
|
+
```
|
197
|
+
でデーターを取得して
|
198
|
+
```c#
|
199
|
+
using System.Collections;
|
200
|
+
using System.Collections.Generic;
|
201
|
+
using UnityEngine;
|
202
|
+
using UnityEngine.UI;
|
203
|
+
|
204
|
+
public class OUTPutUI_script : MonoBehaviour
|
205
|
+
{
|
206
|
+
|
207
|
+
static public string title;
|
208
|
+
|
209
|
+
static public string advice;
|
210
|
+
|
211
|
+
static public string img;
|
212
|
+
|
213
|
+
static public string today_weather;
|
214
|
+
static public string today_date;
|
215
|
+
static public string today_dateLabel;
|
216
|
+
|
217
|
+
static public string tomorrow_weather;
|
218
|
+
static public string tomorrow_date;
|
219
|
+
static public string tomorrow_dateLabel;
|
220
|
+
|
221
|
+
static public string afterTomorrow_weather;
|
222
|
+
static public string afterTomorrow_date;
|
223
|
+
static public string afterTomorrow_dateLabel;
|
224
|
+
|
225
|
+
public Text Title;
|
226
|
+
|
227
|
+
public Text Advice;
|
228
|
+
|
229
|
+
public Text Today_weather;
|
230
|
+
public Text Today_date;
|
231
|
+
public Text Today_dateLabel;
|
232
|
+
|
233
|
+
public Text Tomorrow_weather;
|
234
|
+
public Text Tomorrow_dat;
|
235
|
+
public Text Tomorrow_dateLabel;
|
236
|
+
|
237
|
+
public Text AfterTomorrow_weather;
|
238
|
+
public Text AfterTomorrow_dat;
|
239
|
+
public Text AfterTomorrow_dateLabe;
|
240
|
+
|
241
|
+
// Start is called before the first frame update
|
242
|
+
void Start()
|
243
|
+
{
|
244
|
+
|
245
|
+
}
|
246
|
+
|
247
|
+
// Update is called once per frame
|
248
|
+
void Update()
|
249
|
+
{
|
250
|
+
|
251
|
+
if (System_script.switch_jg == "1")
|
252
|
+
{
|
253
|
+
SwitchON();
|
254
|
+
}
|
255
|
+
|
256
|
+
}
|
257
|
+
public void SwitchON()
|
258
|
+
{
|
259
|
+
Title.text = title;
|
260
|
+
|
261
|
+
Advice.text = advice;
|
262
|
+
|
263
|
+
Today_date.text = today_date;
|
264
|
+
Today_weather.text = today_weather;
|
265
|
+
Today_dateLabel.text = today_dateLabel;
|
266
|
+
|
267
|
+
Tomorrow_dat.text = tomorrow_date;
|
268
|
+
Tomorrow_weather.text = tomorrow_weather;
|
269
|
+
Tomorrow_dateLabel.text = tomorrow_dateLabel;
|
270
|
+
|
271
|
+
AfterTomorrow_dat.text = afterTomorrow_date;
|
272
|
+
AfterTomorrow_weather.text = afterTomorrow_weather;
|
273
|
+
AfterTomorrow_dateLabe.text = afterTomorrow_dateLabel;
|
274
|
+
}
|
275
|
+
}
|
276
|
+
|
277
|
+
```
|
278
|
+
で出力しています
|
279
|
+
上のjsonデーターは取得したデーターの中の自分が取り出せなくて困っている部分だけを書き出した物です。
|
280
|
+
|
281
|
+
追記遅くなってしまってごめんなさい。
|