I have a JSON document like so:
{
dates = {
01 = {
date = "01-07-2013";
prayers = {
Asr = "5:33";
Dhuhr = "1:10";
Fajr = "2:38";
Isha = "11:34";
Maghrib = "9:29";
Qiyam = "1:37";
Sunrise = "4:50";
};
};
02 = {
date = "02-07-2013";
prayers = {
Asr = "5:33";
Dhuhr = "1:10";
Fajr = "2:38";
Isha = "11:34";
Maghrib = "9:29";
Qiyam = "1:37";
Sunrise = "4:51";
};
};
};
location = "London";
}
I need to pull out the value for Fajr
in day 02
(sometimes a different day, the JSON contains all days of month).
My code so far is this:
if(jsonData != nil)
{
NSError *error = nil;
id result = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
NSLog(@"%@", result);
NSLog(@"finished");
if (error == nil) {
NSLog(@"finished");
for (NSMutableDictionary *itemDict in result[@"dates"]) {
NSLog(@"finished");
NSLog(@"item dict: %@", itemDict);
if ([itemDict isEqual: @"02"]) {
//is dates
NSLog(@"is 02");
///the next bit of code is wrong, needs fixing
for (NSMutableDictionary *datesDict in itemDict[@"prayers"]) {
if ([datesDict isEqual: @"Fajr"]) {
NSString *morningTimeOfFajr = datesDict;
NSLog(@"time of Fajr: %@", morningTimeOfFajr);
}
}
}
}
}
}
Now this kind of works to pull out the data for dates
, but how can I drill down to get to one element within a given day?
Many thanks!