以下のコードが前提となるデーターです。
json
1{ 2 "forecasts": [ 3 { 4 "dateLabel": "明日", 5 "telop": "曇のち雨", 6 "date": "2019-02-22", 7 "temperature": { 8 "min": { 9 "celsius": "5", 10 "fahrenheit": "41.0" 11 }, 12 "max": { 13 "celsius": "14", 14 "fahrenheit": "57.2" 15 } 16 }, 17 "image": { 18 "width": 50, 19 "url": "http://weather.livedoor.com/img/icon/13.gif", 20 "title": "曇のち雨", 21 "height": 31 22 } 23 }, 24 ], 25}
この中のtemperatureの中のminの中のfahrenheitが取得したいのですがどうしても取得できませんでした。やり方を知っていたら教えて下さい、よろしくお願いします。
追記
自分が書いていたコードです
c#
1using System; 2using System.Collections; 3using System.Collections.Generic; 4using System.Text; 5using UnityEngine; 6using UnityEngine.Events; 7using UnityEngine.UI; 8using MiniJSON; 9using JsonData; 10 11public class WeatherAPI_test1 : MonoBehaviour 12{ 13 14 static public string url = "http://weather.livedoor.com/forecast/webservice/json/v1?city=400040";//天気URL 15 16 string advis; 17 string image; 18 19 void Start() 20 { 21 22 StartCoroutine("connectdata"); 23 } 24 25 private IEnumerator connectdata() 26 { 27 WWW www = new WWW(url); 28 yield return www; 29 if (!string.IsNullOrEmpty(www.error)) 30 { 31 32 print("Error downloading: " + www.error); 33 34 } 35 else 36 { 37 38 string jsonText = www.text;//受け取ったデーターをjsonTextにIN 39 40 JsonDataClass jsonDataClass; 41 JsonDataClas_image jsonDataClas_image; 42 43 jsonDataClass = JsonUtility.FromJson<JsonDataClass>(jsonText); 44 45 46 Debug.Log(jsonText); 47 48 var json = jsonText; 49 //(1階層目) 50 var jsonData = MiniJSON.Json.Deserialize(json) as Dictionary<string, object>;//全体の並列取得 51 //(2階層目) 52 var description = jsonData["description"] as Dictionary<string, object>;//天気概況文の配列 53 var forecasts = (IList)jsonData["forecasts"];//府県天気予報の予報日毎の配列 54 var pinpointLocations = (IList)jsonData["pinpointLocations"];//ピンポイント予報の発表地点の配列 55 var location = jsonData["location"] as Dictionary<string, object>;//予報を発表した地域を定義 56 57 58 59 60 61 //(3階層目) 62 var forecasts_0 = (IDictionary)forecasts[0]; 63 var forecasts_1 = (IDictionary)forecasts[1]; 64 var forecasts_2 = (IDictionary)forecasts[2]; 65 66 67 68 var pinpointLocations_0 = (IDictionary)pinpointLocations[0]; 69 var pinpointLocations_1 = (IDictionary)pinpointLocations[1]; 70 var pinpointLocations_2 = (IDictionary)pinpointLocations[2]; 71 var pinpointLocations_3 = (IDictionary)pinpointLocations[3]; 72 var pinpointLocations_4 = (IDictionary)pinpointLocations[4]; 73 var pinpointLocations_5 = (IDictionary)pinpointLocations[5]; 74 var pinpointLocations_6 = (IDictionary)pinpointLocations[6]; 75 var pinpointLocations_7 = (IDictionary)pinpointLocations[7]; 76 77 78 79 Debug.Log(jsonDataClass.title); 80 OUTPutUI_script.title = jsonDataClass.title; 81 82 advis = (string)description["text"]; 83 84 OUTPutUI_script.advice = advis.Replace("\n", ""); 85 86 OUTPutUI_script.today_dateLabel = (string)forecasts_0["dateLabel"]; 87 OUTPutUI_script.today_weather = (string)forecasts_0["telop"]; 88 OUTPutUI_script.today_date = (string)forecasts_0["date"]; 89 90 OUTPutUI_script.tomorrow_dateLabel = (string)forecasts_1["dateLabel"]; 91 OUTPutUI_script.tomorrow_weather = (string)forecasts_1["telop"]; 92 OUTPutUI_script.tomorrow_date = (string)forecasts_1["date"]; 93 94 OUTPutUI_script.afterTomorrow_dateLabel = (string)forecasts_2["dateLabel"]; 95 OUTPutUI_script.afterTomorrow_weather = (string)forecasts_2["telop"]; 96 OUTPutUI_script.afterTomorrow_date = (string)forecasts_2["date"]; 97 98 Debug.Log((string)forecasts_0["dateLabel"]);//予報日(今日、明日、明後日のいずれか) 99 Debug.Log((string)forecasts_0["telop"]);//天気 100 Debug.Log((string)forecasts_0["date"]);//予報日 101 102 Debug.Log((string)forecasts_1["dateLabel"]);//予報日(今日、明日、明後日のいずれか) 103 Debug.Log((string)forecasts_1["telop"]);//天気 104 Debug.Log((string)forecasts_1["date"]);//予報日 105 106 107 108 // Debug.Log((string)forecasts_2["dateLabel"]);//予報日(今日、明日、明後日のいずれか) 109 // Debug.Log((string)forecasts_2["telop"]);//天気 110 // Debug.Log((string)forecasts_2["date"]);//予報日 111 112 Debug.Log((string)pinpointLocations_0["link"]);//リンク 113 Debug.Log((string)pinpointLocations_0["name"]);//リンク 114 Debug.Log((string)pinpointLocations_1["link"]);//リンク 115 Debug.Log((string)pinpointLocations_1["name"]);//リンク 116 117 Debug.Log((string)description["text"]);//天気概況本文 118 Debug.Log((string)description["publicTime"]);//天気概況文の発表時刻 119 120 121 122 // Debug.Log((double)location["city"]);//都市 123 Debug.Log((string)location["area"]);//地方名(例・九州地方) 124 Debug.Log((string)location["prefecture"]);//都道府県名(例・福岡県) 125 Debug.Log((string)location["city"]);//1次細分区名(例・八幡) 126 127 128 129 // Debug.Log((double)main["temp_max"]);//最高気温 130 // Debug.Log((double)coord["lon"]);//経度 131 // Debug.Log((double)main["pressure"]);//気圧 132 // Debug.Log((long)main["humidity"]);//湿度 133 // Debug.Log((double)wind["speed"]);//風速 134 // Debug.Log((string)jsonData["name"]);//都市名 135 // Debug.Log((string)sys["country"]);//国名 136 // Debug.Log((long)sys["sunrise"]);//日の出時間 137 // Debug.Log((long)sys["sunset"]);//日没時間 138 139 140 } 141 } 142} 143namespace JsonData 144{ 145 public class JsonDataClass 146 { 147 148 public string publicTime;//予報の発表日時 149 150 public string title;//タイトル・見出し 151 152 public string link; 153 154 public string telop; 155 156 } 157 public class JsonDataClas_image 158 { 159 public string image; 160 } 161}
でデーターを取得して
c#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using UnityEngine.UI; 5 6public class OUTPutUI_script : MonoBehaviour 7{ 8 9 static public string title; 10 11 static public string advice; 12 13 static public string img; 14 15 static public string today_weather; 16 static public string today_date; 17 static public string today_dateLabel; 18 19 static public string tomorrow_weather; 20 static public string tomorrow_date; 21 static public string tomorrow_dateLabel; 22 23 static public string afterTomorrow_weather; 24 static public string afterTomorrow_date; 25 static public string afterTomorrow_dateLabel; 26 27 public Text Title; 28 29 public Text Advice; 30 31 public Text Today_weather; 32 public Text Today_date; 33 public Text Today_dateLabel; 34 35 public Text Tomorrow_weather; 36 public Text Tomorrow_dat; 37 public Text Tomorrow_dateLabel; 38 39 public Text AfterTomorrow_weather; 40 public Text AfterTomorrow_dat; 41 public Text AfterTomorrow_dateLabe; 42 43 // Start is called before the first frame update 44 void Start() 45 { 46 47 } 48 49 // Update is called once per frame 50 void Update() 51 { 52 53 if (System_script.switch_jg == "1") 54 { 55 SwitchON(); 56 } 57 58 } 59 public void SwitchON() 60 { 61 Title.text = title; 62 63 Advice.text = advice; 64 65 Today_date.text = today_date; 66 Today_weather.text = today_weather; 67 Today_dateLabel.text = today_dateLabel; 68 69 Tomorrow_dat.text = tomorrow_date; 70 Tomorrow_weather.text = tomorrow_weather; 71 Tomorrow_dateLabel.text = tomorrow_dateLabel; 72 73 AfterTomorrow_dat.text = afterTomorrow_date; 74 AfterTomorrow_weather.text = afterTomorrow_weather; 75 AfterTomorrow_dateLabe.text = afterTomorrow_dateLabel; 76 } 77} 78
で出力しています
上のjsonデーターは取得したデーターの中の自分が取り出せなくて困っている部分だけを書き出した物です。
追記遅くなってしまってごめんなさい。