clement
clement

Reputation: 4266

NSException during a objectAtIndex

I'm using HTTP request for my iPhone App. When I want to made the dictionnary, there is a NSException...

[__NSCFDictionary objectAtIndex:]: unrecognized selector

Here's the code for the connectionDidFinishLoading :

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[connection release];

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

NSLog(@"responseString");
NSLog(responseString);

[responseData release];
NSArray *tableau = [responseString JSONValue];
NSLog(@"the newt line give me the exception");
NSDictionary *dico = [tableau objectAtIndex:0];

responseString give me that:

{"token":"8569fe2e095d83a4692812fa808f84da"}

I used that code before but it want not run with those datas...

If you can help me, it would be very nice! Thank You !

Upvotes: 1

Views: 231

Answers (1)

user557219
user557219

Reputation:

Arrays in JSON are delimited by [], whilst objects/dictionaries are delimited by {}. Since your response is

{"token":"8569fe2e095d83a4692812fa808f84da"}

it is not an array — it’s a single object/dictionary.

Try:

NSDictionary *dico = [responseString JSONValue];

Upvotes: 2

Related Questions