我有一个具有以下结构的网络服务。
{
"media": {
"albums": [
{
"name": "FC Bazel - KRC Genk",
"date": "04.10.2012",
"pictures": [
{
"url": "http://www.krcgenk.be/images/gallery/album_198/800X600/8162f172f8e5739c535c97b7bb6ca276.jpg"
},
{
"url": "http://www.krcgenk.be/images/gallery/album_198/800X600/5635d20351aacef78563dee347468227.jpg"
}
]
我将我的相册和图片保存在我的核心数据数据库中的单独实体中。我得到以下值。
+ (NSArray *)getAlbums
{
NSString *request = [NSString stringWithFormat:@"http://www.krcgenk.be/mobile/json/request/media/type/ipad"];
return [[self executeGenkFetch:request] valueForKeyPath:@"media.albums"];
}
+ (NSArray *)getPictures
{
NSString *request = [NSString stringWithFormat:@"http://www.krcgenk.be/mobile/json/request/media/type/ipad"];
return [[self executeGenkFetch:request] valueForKeyPath:@"media.albums.pictures"];
}
我定义如下的值。
#define ALBUMS_NAME @"name"
#define ALBUMS_DATE @"date"
#define PICTURES_URL @"pictures.url"
所有的东西都适合专辑。但是当它试图获取图片中的 url 时,它会因以下错误而崩溃。
__NSArrayI objectForKey:]: unrecognized selector sent to instance 0xa48a460
2012-10-05 17:06:50.201 RacingGenk[97248:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI objectForKey:]: unrecognized selector sent to instance 0xa48a460
有人可以帮忙吗?
亲切的问候。
- - -编辑 - -
+ (Picture *)pictureWithGenkInfo:(NSDictionary *)genkInfo
inManagedObjectContext:(NSManagedObjectContext *)context
withAlbumId:(int)albumId
withPictureId:(int)pictureId;
{
Picture *picture = nil;
picture = [NSEntityDescription insertNewObjectForEntityForName:@"Picture"
inManagedObjectContext:context];
NSLog(@"methode komt tot hier");
picture.url = [genkInfo objectForKey:PICTURES_URL];
return picture
}
'