I have a webservice with the following structure.
{
"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"
}
]
I am saving my Albums and Pictures in a separate entity in my core data database. I am getting the values the following.
+ (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"];
}
And I define the values like following.
#define ALBUMS_NAME @"name"
#define ALBUMS_DATE @"date"
#define PICTURES_URL @"pictures.url"
All things work great for albums. But when it tries to get the url in pictures, it crashes with the following error.
__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
Can someone help?
Kind regards.
—–EDIT—-
+ (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
}
‘
You can get the albums with media.albums because albums is the value for the key “media”, but “pictures” is not the value of the key albums — the value is an array (hence your error message) of dictionaries. I don’t know if this will work, but you could try this: