.m:
@implementation ViewController
{
NSDictionary *_json;
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL* url = [NSURL URLWithString:@"http://api.worldweatheronline.com/free/v1/weather.ashx?q=Si%C3%B3fok&format=json&num_of_days=5&key=mykey"];
NSData *jsonData = [NSData dataWithContentsOfURL:url];
NSError *error;
_json = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
NSDictionary* fullDictFromjson = _json[@"data"];
NSLog(@"%@",fullDictFromjson);
NSDictionary* currentCondition = fullDictFromjson[@"current_condition"];
NSLog(@"%@",currentCondition);
この後、コンソールでこれを取得しました( currentCondition ):
2013-04-18 22:18:16.758 weather[18111:c07] (
{
cloudcover = 0;
humidity = 74;
"observation_time" = "08:18 PM";
precipMM = "0.0";
pressure = 1019;
"temp_C" = 11;
"temp_F" = 51;
visibility = 10;
weatherCode = 113;
weatherDesc = (
{
value = Clear;
}
);
weatherIconUrl = (
{
value = "http://www.worldweatheronline.com/images/wsymbols01_png_64/wsymbol_0008_clear_sky_night.png";
}
);
winddir16Point = S;
winddirDegree = 170;
windspeedKmph = 5;
windspeedMiles = 3;
}
)
そして、私はこれを扱うことができません。
この URL を Safari で開いた場合:
"current_condition": [ {"cloudcover": "0", ..... したがって、"(" ではなく "[" が存在します。
だから私のjsonはxcodeで間違っています
私は何をすべきか?