0
votes

In this code:

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {      

//---initialize the array--- 
listOfJMovies = [[NSMutableArray alloc] init];
listOfJMoviePosters = [[NSMutableArray alloc] init];
tmdbMovies = [[NSArray alloc] init];
posters = [[NSArray alloc] init];
thumbs = [[NSArray alloc] init];

//---set the title--- 
self.navigationItem.title = @"Movies";

NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];

//NSLog(responseString);

SBJsonParser *json = [[SBJsonParser new] autorelease];
tmdbMovies = [json objectWithString:responseString error:nil];

for (id movie in tmdbMovies) {
    [listOfJMovies addObject:[movie objectForKey:@"name"]];
    NSLog(@"Name: %@", [movie objectForKey:@"name"]);
    //[listOfJMoviePosters addObject:[obj objectForKey:@"posters"]];
    //NSLog(@"%@", [obj objectForKey:@"posters"]);

    posters = [movie objectForKey:@"posters"];

    for (id image in posters) {
        NSLog(@"image: %@", [image objectForKey:@"image"]);
        thumbs = [image objectForKey:@"image"];

        for (id url in thumbs) {


            NSLog(@"Size: %@", [url objectForKey:@"size"]);

            //NSLog(@"blah");
            //[listOfJMoviePosters addObject:[url objectForKey:@"size"]];

        }



    }

}


[[self tableView] reloadData];

[responseString release];
[connection release];
[responseData release];


}

This line: NSLog(@"Size: %@", [url objectForKey:@"size"]);

Is causing the app to crash and throw the following error:

2010-12-30 00:33:29.730 FlixIt[33132:207] -[NSCFString objectForKey:]: unrecognized selector sent to instance 0x4e50f00 2010-12-30 00:33:29.732 FlixIt[33132:207] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString objectForKey:]: unrecognized selector sent to instance 0x4e50f00'

Here is the JSON: http://api.themoviedb.org/2.1/Movie.browse/en-US/json/e5084159b962a8f0c39096f379a1363c?order_by=rating&order=desc&genres=18&min_votes=5&page=1&per_page=10

3

3 Answers

2
votes

From looking into the data structure, it seems to me that you have one extra loop. In the "posters" loop try:

for (id image in posters) {
    NSLog(@"image: %@", [image objectForKey:@"image"]);
    thumbs = [image objectForKey:@"image"];


    NSLog(@"Size: %@", [thumbs objectForKey:@"size"]);

}

image is a dictionary and the key "size" has NSString type.

1
votes

By the looks of it url is of type NSString which doesn't respond to the method objectForKey:. In other words, that method is not implemented by NSString. If you know the types of the objects you are expecting in your for loops then you would gain some additional compiler checks if you used the specific type in the declaration instead of id.

I am not familiar with SBJSonParser, but I assume that most of the things you are manipulating are returned as NSDictionary, which specific fields being returned as more detailed types (e.g. strings as NSString).

I also assume that by querying 'size' you are actually looking for the length of the string? In that case you need to be using the length method. If that's not what you are trying to do, then some more information would be useful.

By way of example I have pulled out a short section of your code.

for (NSDictionary *image in posters) {
    NSLog(@"image: %@", [image objectForKey:@"image"]);
    thumbs = [image objectForKey:@"image"];

    for (NSString *url in thumbs) {
        NSLog(@"Size: %@", [url length]);

        //NSLog(@"blah");
        //[listOfJMoviePosters addObject:[url objectForKey:@"size"]];

    }
}
0
votes

Hope this helps someone.

This is not a code answer, but I was getting this exact error message and I FIXED IT BY :

*1 - Clean build folder

*2 - Clear derived data

*3 - Delete the app on your simulator and / or device.

In my case, I added a bunch of frameworks on a different branch. And when I switched branches I needed a deep clean of the project.