i wan't to retrieve the image "url" from this Json : http://api-public.guidebox.com/v1.43/Tunisia/rKgEWJbFg0kgEHrcGXPKhPDo0XtTafyC/search/person/name/kelly/fuzzy my Json have this format : results […images {small { url }}] can any one check with me this code please Any one to help me please
- (void)viewDidLoad {
[super viewDidLoad];
_tableData=[[NSMutableArray alloc]initWithCapacity:50] ;
_tab.delegate=self;
_tab.dataSource=self;
_tab.backgroundColor = [UIColor clearColor];
NSURL *url = [NSURL URLWithString:BaseURLStringg];
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
[manager GET:url.absoluteString parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
// NSLog(@"JSON: %@", responseObject);
NSDictionary *jsonDict = (NSDictionary *) responseObject;
NSArray *products = [jsonDict objectForKey:@"results"];
[products enumerateObjectsUsingBlock:^(id obj,NSUInteger idx, BOOL *stop){
NSString *name= [NSString stringWithFormat:@"%@ ", [obj objectForKey:@"name"] ];
// poster= [NSString stringWithFormat:@"%@ ", [obj objectForKey:@"url"] ];
poster=[NSString stringWithFormat:@"%@ ", [[[obj objectForKey:@"images"]objectForKey:@"small"]objectForKey:@"url"]];
NSLog(poster);
NSDictionary *movieDictionary = @{@"name":name,
@"url":poster};
[self.tableData addObject:movieDictionary];
[self.tab reloadData];
}];
/*dispatch_sync(dispatch_get_main_queue(), ^{
self.tableData=[[NSMutableArray alloc]initWithArray:responseObject];
[self.tab reloadData]; });
}*/
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"Error: %@", error);
}];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [self.tableData count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell* mycell=[tableView dequeueReusableCellWithIdentifier:@"myCell" forIndexPath:indexPath];
// NSInteger nameindex=[_DB.arrColumnNames indexOfObject:@"name"];
//NSString* name=[[_myarray objectAtIndex:indexPath.row] objectAtIndex:nameindex];
UILabel *name = [mycell.contentView viewWithTag:101];
UIImageView *posterImage=[mycell.contentView viewWithTag:102];
/* title.text= [_tableData objectAtIndex:indexPath.row];
release_year.text= [_tableData objectAtIndex:indexPath.row];
themoviedb.text= [_tableData objectAtIndex:indexPath.row];
original_title.text= [_tableData objectAtIndex:indexPath.row];*/
NSDictionary *movieDictionary = self.tableData[indexPath.row];
name.text= movieDictionary[@"name"];
//mycell.textLabel.text=@"eererr";
NSString *finalURL = movieDictionary[@"url"];
finalURL = [finalURL stringByReplacingOccurrencesOfString:@"\\" withString:@""];
finalURL = [finalURL stringByReplacingOccurrencesOfString:@" " withString:@""];
NSString *cleanedUrl = [finalURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:cleanedUrl]];
[posterImage setImage: [UIImage imageWithData:imageData]];
mycell.textLabel.textColor = [UIColor blackColor];
mycell.contentView.backgroundColor = [UIColor clearColor];
mycell.backgroundColor = [UIColor clearColor];
return mycell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath{
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
this my Json file
"results":[
{
"id":197753,
"name":"Kelly Hu",
"wikipedia_id":20646206,
"freebase":"/m/03l7xc",
"imdb":"nm0005026",
"themoviedb":11024,
"tvrage":497,
"social":{
"twitter":{
"twitter_id":51649635,
"link":"https://twitter.com/KellyHu"
}
},
"images":{
"small":{
"url":"http://static-api.guidebox.com/091414/thumbnails_people/29984-7234075409-1208944377-2556317393-small-135x200.jpg",
"width":135,
"height":200
},