我得到的JSON對象從https://twitter.com/statuses/public_timeline.json使用NSJSONSerialization
所以顯示的數據,我的代碼是下一個:
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url = [NSURL URLWithString:@"https://twitter.com/statuses/public_timeline.json"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
students = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
for(NSDictionary *item in students) {
NSLog(@"Message: %@", [item objectForKey:@"message"]);
}
}
所以,我得到了一個錯誤:
2013-01-23 21:42:02.672 students[94907:11603] -[__NSCFString objectForKey:]: unrecognized selector sent to instance 0x7471580
2013-01-23 21:42:02.681 students[94907:11603] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString objectForKey:]: unrecognized selector sent to instance 0x7471580'
是的,我有嘗試過,我可以看到「錯誤」,但是我想要顯示每個字段作爲e的消息xample。 – grouser