質問編集履歴

1

自分の書いたコードの追加

2019/02/28 02:04

投稿

nitiyoubi
nitiyoubi

スコア10

test CHANGED
@@ -1 +1 @@
1
- unity(C#)でjson取得したデーターの一部を取得したい
1
+ unity(C#)でjson取得したデーター[ { { 個々 } } ] データーを取得したい
test CHANGED
@@ -55,3 +55,507 @@
55
55
  ```
56
56
 
57
57
  この中のtemperatureの中のminの中のfahrenheitが取得したいのですがどうしても取得できませんでした。やり方を知っていたら教えて下さい、よろしくお願いします。
58
+
59
+
60
+
61
+
62
+
63
+ 追記
64
+
65
+ 自分が書いていたコードです
66
+
67
+ ```c#
68
+
69
+ using System;
70
+
71
+ using System.Collections;
72
+
73
+ using System.Collections.Generic;
74
+
75
+ using System.Text;
76
+
77
+ using UnityEngine;
78
+
79
+ using UnityEngine.Events;
80
+
81
+ using UnityEngine.UI;
82
+
83
+ using MiniJSON;
84
+
85
+ using JsonData;
86
+
87
+
88
+
89
+ public class WeatherAPI_test1 : MonoBehaviour
90
+
91
+ {
92
+
93
+
94
+
95
+ static public string url = "http://weather.livedoor.com/forecast/webservice/json/v1?city=400040";//天気URL
96
+
97
+
98
+
99
+ string advis;
100
+
101
+ string image;
102
+
103
+
104
+
105
+ void Start()
106
+
107
+ {
108
+
109
+
110
+
111
+ StartCoroutine("connectdata");
112
+
113
+ }
114
+
115
+
116
+
117
+ private IEnumerator connectdata()
118
+
119
+ {
120
+
121
+ WWW www = new WWW(url);
122
+
123
+ yield return www;
124
+
125
+ if (!string.IsNullOrEmpty(www.error))
126
+
127
+ {
128
+
129
+
130
+
131
+ print("Error downloading: " + www.error);
132
+
133
+
134
+
135
+ }
136
+
137
+ else
138
+
139
+ {
140
+
141
+
142
+
143
+ string jsonText = www.text;//受け取ったデーターをjsonTextにIN
144
+
145
+
146
+
147
+ JsonDataClass jsonDataClass;
148
+
149
+ JsonDataClas_image jsonDataClas_image;
150
+
151
+
152
+
153
+ jsonDataClass = JsonUtility.FromJson<JsonDataClass>(jsonText);
154
+
155
+
156
+
157
+
158
+
159
+ Debug.Log(jsonText);
160
+
161
+
162
+
163
+ var json = jsonText;
164
+
165
+ //(1階層目)
166
+
167
+ var jsonData = MiniJSON.Json.Deserialize(json) as Dictionary<string, object>;//全体の並列取得
168
+
169
+ //(2階層目)
170
+
171
+ var description = jsonData["description"] as Dictionary<string, object>;//天気概況文の配列
172
+
173
+ var forecasts = (IList)jsonData["forecasts"];//府県天気予報の予報日毎の配列
174
+
175
+ var pinpointLocations = (IList)jsonData["pinpointLocations"];//ピンポイント予報の発表地点の配列
176
+
177
+ var location = jsonData["location"] as Dictionary<string, object>;//予報を発表した地域を定義
178
+
179
+
180
+
181
+
182
+
183
+
184
+
185
+
186
+
187
+
188
+
189
+ //(3階層目)
190
+
191
+ var forecasts_0 = (IDictionary)forecasts[0];
192
+
193
+ var forecasts_1 = (IDictionary)forecasts[1];
194
+
195
+ var forecasts_2 = (IDictionary)forecasts[2];
196
+
197
+
198
+
199
+
200
+
201
+
202
+
203
+ var pinpointLocations_0 = (IDictionary)pinpointLocations[0];
204
+
205
+ var pinpointLocations_1 = (IDictionary)pinpointLocations[1];
206
+
207
+ var pinpointLocations_2 = (IDictionary)pinpointLocations[2];
208
+
209
+ var pinpointLocations_3 = (IDictionary)pinpointLocations[3];
210
+
211
+ var pinpointLocations_4 = (IDictionary)pinpointLocations[4];
212
+
213
+ var pinpointLocations_5 = (IDictionary)pinpointLocations[5];
214
+
215
+ var pinpointLocations_6 = (IDictionary)pinpointLocations[6];
216
+
217
+ var pinpointLocations_7 = (IDictionary)pinpointLocations[7];
218
+
219
+
220
+
221
+
222
+
223
+
224
+
225
+ Debug.Log(jsonDataClass.title);
226
+
227
+ OUTPutUI_script.title = jsonDataClass.title;
228
+
229
+
230
+
231
+ advis = (string)description["text"];
232
+
233
+
234
+
235
+ OUTPutUI_script.advice = advis.Replace("\n", "");
236
+
237
+
238
+
239
+ OUTPutUI_script.today_dateLabel = (string)forecasts_0["dateLabel"];
240
+
241
+ OUTPutUI_script.today_weather = (string)forecasts_0["telop"];
242
+
243
+ OUTPutUI_script.today_date = (string)forecasts_0["date"];
244
+
245
+
246
+
247
+ OUTPutUI_script.tomorrow_dateLabel = (string)forecasts_1["dateLabel"];
248
+
249
+ OUTPutUI_script.tomorrow_weather = (string)forecasts_1["telop"];
250
+
251
+ OUTPutUI_script.tomorrow_date = (string)forecasts_1["date"];
252
+
253
+
254
+
255
+ OUTPutUI_script.afterTomorrow_dateLabel = (string)forecasts_2["dateLabel"];
256
+
257
+ OUTPutUI_script.afterTomorrow_weather = (string)forecasts_2["telop"];
258
+
259
+ OUTPutUI_script.afterTomorrow_date = (string)forecasts_2["date"];
260
+
261
+
262
+
263
+ Debug.Log((string)forecasts_0["dateLabel"]);//予報日(今日、明日、明後日のいずれか)
264
+
265
+ Debug.Log((string)forecasts_0["telop"]);//天気
266
+
267
+ Debug.Log((string)forecasts_0["date"]);//予報日
268
+
269
+
270
+
271
+ Debug.Log((string)forecasts_1["dateLabel"]);//予報日(今日、明日、明後日のいずれか)
272
+
273
+ Debug.Log((string)forecasts_1["telop"]);//天気
274
+
275
+ Debug.Log((string)forecasts_1["date"]);//予報日
276
+
277
+
278
+
279
+
280
+
281
+
282
+
283
+ // Debug.Log((string)forecasts_2["dateLabel"]);//予報日(今日、明日、明後日のいずれか)
284
+
285
+ // Debug.Log((string)forecasts_2["telop"]);//天気
286
+
287
+ // Debug.Log((string)forecasts_2["date"]);//予報日
288
+
289
+
290
+
291
+ Debug.Log((string)pinpointLocations_0["link"]);//リンク
292
+
293
+ Debug.Log((string)pinpointLocations_0["name"]);//リンク
294
+
295
+ Debug.Log((string)pinpointLocations_1["link"]);//リンク
296
+
297
+ Debug.Log((string)pinpointLocations_1["name"]);//リンク
298
+
299
+
300
+
301
+ Debug.Log((string)description["text"]);//天気概況本文
302
+
303
+ Debug.Log((string)description["publicTime"]);//天気概況文の発表時刻
304
+
305
+
306
+
307
+
308
+
309
+
310
+
311
+ // Debug.Log((double)location["city"]);//都市
312
+
313
+ Debug.Log((string)location["area"]);//地方名(例・九州地方)
314
+
315
+ Debug.Log((string)location["prefecture"]);//都道府県名(例・福岡県)
316
+
317
+ Debug.Log((string)location["city"]);//1次細分区名(例・八幡)
318
+
319
+
320
+
321
+
322
+
323
+
324
+
325
+ // Debug.Log((double)main["temp_max"]);//最高気温
326
+
327
+ // Debug.Log((double)coord["lon"]);//経度
328
+
329
+ // Debug.Log((double)main["pressure"]);//気圧
330
+
331
+ // Debug.Log((long)main["humidity"]);//湿度
332
+
333
+ // Debug.Log((double)wind["speed"]);//風速
334
+
335
+ // Debug.Log((string)jsonData["name"]);//都市名
336
+
337
+ // Debug.Log((string)sys["country"]);//国名
338
+
339
+ // Debug.Log((long)sys["sunrise"]);//日の出時間
340
+
341
+ // Debug.Log((long)sys["sunset"]);//日没時間
342
+
343
+
344
+
345
+
346
+
347
+ }
348
+
349
+ }
350
+
351
+ }
352
+
353
+ namespace JsonData
354
+
355
+ {
356
+
357
+ public class JsonDataClass
358
+
359
+ {
360
+
361
+
362
+
363
+ public string publicTime;//予報の発表日時
364
+
365
+
366
+
367
+ public string title;//タイトル・見出し
368
+
369
+
370
+
371
+ public string link;
372
+
373
+
374
+
375
+ public string telop;
376
+
377
+
378
+
379
+ }
380
+
381
+ public class JsonDataClas_image
382
+
383
+ {
384
+
385
+ public string image;
386
+
387
+ }
388
+
389
+ }
390
+
391
+ ```
392
+
393
+ でデーターを取得して
394
+
395
+ ```c#
396
+
397
+ using System.Collections;
398
+
399
+ using System.Collections.Generic;
400
+
401
+ using UnityEngine;
402
+
403
+ using UnityEngine.UI;
404
+
405
+
406
+
407
+ public class OUTPutUI_script : MonoBehaviour
408
+
409
+ {
410
+
411
+
412
+
413
+ static public string title;
414
+
415
+
416
+
417
+ static public string advice;
418
+
419
+
420
+
421
+ static public string img;
422
+
423
+
424
+
425
+ static public string today_weather;
426
+
427
+ static public string today_date;
428
+
429
+ static public string today_dateLabel;
430
+
431
+
432
+
433
+ static public string tomorrow_weather;
434
+
435
+ static public string tomorrow_date;
436
+
437
+ static public string tomorrow_dateLabel;
438
+
439
+
440
+
441
+ static public string afterTomorrow_weather;
442
+
443
+ static public string afterTomorrow_date;
444
+
445
+ static public string afterTomorrow_dateLabel;
446
+
447
+
448
+
449
+ public Text Title;
450
+
451
+
452
+
453
+ public Text Advice;
454
+
455
+
456
+
457
+ public Text Today_weather;
458
+
459
+ public Text Today_date;
460
+
461
+ public Text Today_dateLabel;
462
+
463
+
464
+
465
+ public Text Tomorrow_weather;
466
+
467
+ public Text Tomorrow_dat;
468
+
469
+ public Text Tomorrow_dateLabel;
470
+
471
+
472
+
473
+ public Text AfterTomorrow_weather;
474
+
475
+ public Text AfterTomorrow_dat;
476
+
477
+ public Text AfterTomorrow_dateLabe;
478
+
479
+
480
+
481
+ // Start is called before the first frame update
482
+
483
+ void Start()
484
+
485
+ {
486
+
487
+
488
+
489
+ }
490
+
491
+
492
+
493
+ // Update is called once per frame
494
+
495
+ void Update()
496
+
497
+ {
498
+
499
+
500
+
501
+ if (System_script.switch_jg == "1")
502
+
503
+ {
504
+
505
+ SwitchON();
506
+
507
+ }
508
+
509
+
510
+
511
+ }
512
+
513
+ public void SwitchON()
514
+
515
+ {
516
+
517
+ Title.text = title;
518
+
519
+
520
+
521
+ Advice.text = advice;
522
+
523
+
524
+
525
+ Today_date.text = today_date;
526
+
527
+ Today_weather.text = today_weather;
528
+
529
+ Today_dateLabel.text = today_dateLabel;
530
+
531
+
532
+
533
+ Tomorrow_dat.text = tomorrow_date;
534
+
535
+ Tomorrow_weather.text = tomorrow_weather;
536
+
537
+ Tomorrow_dateLabel.text = tomorrow_dateLabel;
538
+
539
+
540
+
541
+ AfterTomorrow_dat.text = afterTomorrow_date;
542
+
543
+ AfterTomorrow_weather.text = afterTomorrow_weather;
544
+
545
+ AfterTomorrow_dateLabe.text = afterTomorrow_dateLabel;
546
+
547
+ }
548
+
549
+ }
550
+
551
+
552
+
553
+ ```
554
+
555
+ で出力しています
556
+
557
+ 上のjsonデーターは取得したデーターの中の自分が取り出せなくて困っている部分だけを書き出した物です。
558
+
559
+
560
+
561
+ 追記遅くなってしまってごめんなさい。