好的,我对此很陌生,并且一直在努力解决你们可能觉得很容易的练习。我已经四处搜寻,找不到关于如何做到这一点的好的教程或演练。基本上,我使用下面的代码来获取推文,我只想要推文的“文本”部分。如何从 NSDictionary 中提取它以便在 tableview 中使用“text”键?我已经尝试过[dict objectForKey:@"text"]
,但它不起作用 - 'dict' 似乎不包含 'text' 属性。提前感谢您的帮助。
// Do a simple search, using the Twitter API
TWRequest *request = [[TWRequest alloc] initWithURL:[NSURL URLWithString:
@"http://search.twitter.com/search.json?q=iOS%205&rpp=5&with_twitter_user_id=true&result_type=recent"]
parameters:nil requestMethod:TWRequestMethodGET];
// Notice this is a block, it is the handler to process the response
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
{
if ([urlResponse statusCode] == 200)
{
// The response from Twitter is in JSON format
// Move the response into a dictionary and print
NSError *error;
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:&error];
NSLog(@"Twitter response: %@", dict);
}
else
NSLog(@"Twitter error, HTTP response: %i", [urlResponse statusCode]);
}];