Iphone 解析twitterjson
我编写了一些代码从Twitter搜索中获取数据,并将其放入Iphone 解析twitterjson,iphone,xcode,Iphone,Xcode,我编写了一些代码从Twitter搜索中获取数据,并将其放入UITableView,但我得到一个语法错误,指出No visible@interface for'NSArray'声明选择器'objectForKey: 下面是我用来获取JSON数据的代码: -(void)connectionDidFinishLoading:(NSURLConnection *)connection { NSDictionary *allDataDictionary = [NSJSONSerializatio
UITableView
,但我得到一个语法错误,指出No visible@interface for'NSArray'声明选择器'objectForKey:
下面是我用来获取JSON
数据的代码:
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSDictionary *allDataDictionary = [NSJSONSerialization JSONObjectWithData:webData options:0 error:nil];
NSArray *feed = [allDataDictionary objectForKey:@"results"];
NSString *text = [feed objectForKey:@"text"];
[array addObject:text];
[[self myTableView] reloadData];
}
(按左上角的“查看器”)
有什么帮助吗?谢谢:)这是因为您正在拨打:
NSString *text = [feed objectForKey:@"text"];
仔细观察:
[feed objectForKey:@"text"];
对象feed
是一个NSArray
:
NSArray *feed = [allDataDictionary objectForKey:@"results"];
显然,NSArray
没有方法objectForKey:
,这是一本字典
因此,您可能对Objective-C有输入错误、混淆或误解。NSDictionary*allDataDictionary=[NSJSONSerialization JSONObjectWithData:webData选项:0错误:无];
NSDictionary *allDataDictionary = [NSJSONSerialization JSONObjectWithData:webData options:0 error:nil];
NSArray *feed = [allDataDictionary objectForKey:@"results"];
for (NSDictionary *item in feed) {
NSString *text = [item objectForKey:@"text"];
[array addObject:text]; <- I assume this is NSMutableArray
}
[[self myTableView]reloadData];
NSArray*feed=[allDataDictionary objectForKey:@“结果”];
for(源中的NSDictionary*项){
NSString*text=[item objectForKey:@“text]”;
[array addObject:text];出现语法错误。NSArray没有“objectForKey”方法。