我有一个像这样的 JSON 文档:
{
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";
}
我需要提取Fajr
当天的价值02
的值(有时是不同的一天,JSON 包含一个月中的所有天数)。
到目前为止,我的代码是这样的:
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);
}
}
}
}
}
}
现在这种工作可以提取数据dates
,但是我如何在给定的一天内深入了解一个元素?
非常感谢!