以下代码让我发疯:
-(void)fetchEventDetails
{
NSData *jsonData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://domain.com/ios/read.php"]];
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];
for(id object in dict){
//NSLog(@"city : %@",object[@"city"]);
// NSLog(@"title : %@",object[@"title"]);
// NSLog(@"description : %@",object[@"description"]);
[_eventsTitles addObject:object[@"title"]];
[_eventsCity addObject:object[@"city"]];
}
NSLog(@"Array : %@", _eventsCity);
}
因此,如果我取消注释 for 循环的第一行,它会打印所有城市。如果我打印 NSArray,它显示为空。两者在.h 文件中的定义方式相同,即eventsTitles 和eventsCity。有什么问题?
谢谢您的帮助