objectAtIndex期间的NSException

时间:2011-06-27 12:13:15

标签: iphone xcode dictionary nsarray nsdictionary

我正在使用我的iPhone App的HTTP请求。当我想要制作词典时,有一个NSException ...

[__NSCFDictionary objectAtIndex:]: unrecognized selector

这是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告诉我:

{"token":"8569fe2e095d83a4692812fa808f84da"}

之前我使用过该代码,但它不想使用这些数据...

如果你能帮助我,那将是非常好的! 谢谢!

1 个答案:

答案 0 :(得分:2)

JSON中的数组由[]分隔,而对象/字典由{}分隔。由于您的回复是

{"token":"8569fe2e095d83a4692812fa808f84da"}

它不是数组 - 它是单个对象/字典。

尝试:

NSDictionary *dico = [responseString JSONValue];