我如何从NSDictionary检索值?
我是新来的。 我已经从网站分析了10个值到一个tableview并链接到一个详细视图控制器。 如何在单击每个单元格时显示个别值?
(void)viewDidLoad {
[[self tableView] setDelegate:self]; [[self tableView] setDataSource:self]; array = [[NSMutableArray alloc] init];
[数组removeAllObjects];
NSURL * url = [NSURL URLWithString:@“https://itunes.apple.com/us/rss/topalbums/limit=10/json”]; NSURLRequest * request = [NSURLRequest requestWithURL:url];
connection = [NSURLConnection connectionWithRequest:request delegate:self];
if(connection){webData = [[NSMutableData alloc] init]; }
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {NSDictionary * allDataDictionary = [NSJSONSerialization JSONObjectWithData:webData options:0 error:nil]; NSDictionary * feed = [allDataDictionary objectForKey:@“feed”]; NSArray * arrayOfEntry = [feed objectForKey:@“entry”];
for (NSDictionary *diction in arrayOfEntry){
NSDictionary *title = [diction objectForKey:@"title"];
NSString *label = [title objectForKey:@"label"];
[array addObject:label];
}
[[self tableView] reloadData];
}
JSON数据将采用NSMutableArray
格式。
NSMutableArray *allDataDictionary = [NSJSONSerialization JSONObjectWithData:webData options:0 error:nil];
int i=0;
for (i=0;i<[allDataDictionary count];i++) {
NSLog("value is %@", [NSString stringWithFormat:@"%@", [[allDataDictionary objectAtIndex:i] objectForKey:@"yourKey"]];)
}
链接地址: http://www.djcxy.com/p/72683.html