7

これについてはあまりにも多くの議論がありましたが、それでも問題を解決する方法がわかりません。

これが、WorldWeatherOnlineから取得したJSONデータです。JSONは有効です。しかし、それを解析する方法がわかりません。これは私のコードで、その後にJSONが続きます。助けてください!

NSError* errorInfo;
NSDictionary *parsedJSON = [NSJSONSerialization JSONObjectWithData:self.wwoWeatherData options:kNilOptions error:&errorInfo];

NSArray* temp = [parsedJSON objectForKey:@"temp_C"];
NSLog(@"%@", temp);
   {{
   "データ":{
      "現状":[
         {{
            "cloudcover": "0"、
            「湿度」:「82」、
            "observation_time": "11:07 PM"、
            "precipMM": "0.0"、
            "圧力": "1024"、
            "temp_C": "16"、
            "temp_F": "61"、
            "可視性": "10"、
            "weatherCode": "113"、
            "weatherDesc":[
               {{
                  "値":"クリア"
               }
            ]、
            "weatherIconUrl":[
               {{
                  "値": "http:\ / \ / www.worldweatheronline.com \ / images \ /wsymbols01_png_64 \ /wsymbol_0008_clear_sky_night.png"
               }
            ]、
            "winddir16Point": "NNE"、
            "winddirDegree": "30"、
            "windspeedKmph": "11"、
            "windspeedMiles": "7"
         }
      ]、
      "リクエスト":[
         {{
            "クエリ": "Lat48.85およびLon2.35"、
            "type": "LatLon"
         }
      ]、
      "天気":[
         {{
            "日付": "2012-09-04"、
            "precipMM": "0.0"、
            "tempMaxC": "25"、
            "tempMaxF": "77"、
            "tempMinC": "14"、
            "tempMinF": "57"、
            "weatherCode": "113"、
            "weatherDesc":[
               {{
                  "値":"晴れ"
               }
            ]、
            "weatherIconUrl":[
               {{
                  "値": "http:\ / \ / www.worldweatheronline.com \ / images \ / wsymbols01_png_64 \ /wsymbol_0001_sunny.png"
               }
            ]、
            "winddir16Point": "N"、
            "winddirDegree": "5"、
            "風向": "N"、
            "windspeedKmph": "13"、
            "windspeedMiles": "8"
         }、
         {{
            "日付": "2012-09-05"、
            "precipMM": "0.0"、
            "tempMaxC": "22"、
            "tempMaxF": "72"、
            "tempMinC": "10"、
            "tempMinF": "50"、
            "weatherCode": "113"、
            "weatherDesc":[
               {{
                  "値":"晴れ"
               }
            ]、
            "weatherIconUrl":[
               {{
                  "値": "http:\ / \ / www.worldweatheronline.com \ / images \ / wsymbols01_png_64 \ /wsymbol_0001_sunny.png"
               }
            ]、
            "winddir16Point": "NNE"、
            "winddirDegree": "25"、
            "winddirection": "NNE"、
            "windspeedKmph": "20"、
            "windspeedMiles": "13"
         }、
         {{
            "日付": "2012-09-06"、
            "precipMM": "0.0"、
            "tempMaxC": "22"、
            "tempMaxF": "71"、
            "tempMinC": "11"、
            "tempMinF": "51"、
            "weatherCode": "113"、
            "weatherDesc":[
               {{
                  "値":"晴れ"
               }
            ]、
            "weatherIconUrl":[
               {{
                  "値": "http:\ / \ / www.worldweatheronline.com \ / images \ / wsymbols01_png_64 \ /wsymbol_0001_sunny.png"
               }
            ]、
            "winddir16Point": "NE"、
            "winddirDegree": "42"、
            "風向": "NE"、
            "windspeedKmph": "15"、
            "windspeedMiles": "10"
         }、
         {{
            "日付": "2012-09-07"、
            "precipMM": "0.0"、
            "tempMaxC": "24"、
            "tempMaxF": "75"、
            "tempMinC": "13"、
            "tempMinF": "55"、
            "weatherCode": "116"、
            "weatherDesc":[
               {{
                  "値":"部分的に曇り"
               }
            ]、
            "weatherIconUrl":[
               {{
                  "値": "http:\ / \ / www.worldweatheronline.com \ / images \ /wsymbols01_png_64 \ /wsymbol_0002_sunny_intervals.png"
               }
            ]、
            "winddir16Point": "ENE"、
            "winddirDegree": "56"、
            "風向": "ENE"、
            "windspeedKmph": "13"、
            "windspeedMiles": "8"
         }、
         {{
            "日付": "2012-09-08"、
            "precipMM": "0.0"、
            "tempMaxC": "26"、
            "tempMaxF": "78"、
            "tempMinC": "16"、
            "tempMinF": "61"、
            "weatherCode": "113"、
            "weatherDesc":[
               {{
                  "値":"晴れ"
               }
            ]、
            "weatherIconUrl":[
               {{
                  "値": "http:\ / \ / www.worldweatheronline.com \ / images \ / wsymbols01_png_64 \ /wsymbol_0001_sunny.png"
               }
            ]、
            "winddir16Point": "ENE"、
            "winddirDegree": "76"、
            "風向": "ENE"、
            "windspeedKmph": "9"、
            "windspeedMiles": "6"
         }
      ]
   }
}
4

1 に答える 1

8

解析したjsonには、という名前の辞書が含まれていますdata。その辞書の中にはの配列がありcurrent_conditionます。データ構造をドリルダウンして、探している属性を見つけてください。

NSDictionary *data = [parsedJSON objectForKey:@"data"];
NSArray *currentConditions = [data objectForKey:@"current_condition"];
NSDictionary *condition = [currentConditions objectAtIndex:0];
NSString *tempC = [condition objectForKey:@"temp_C"];
于 2012-09-04T00:12:21.173 に答える