Json Data' da Yer Alan Image URL' leri Parçalayamadım.
Merhabalar, Kod kısmım şöyle;
[code]#import "TableViewController.h"
@interface TableViewController (){
NSMutableData *webData;
NSURLConnection *connection;
NSMutableArray *labelArray;
NSMutableArray *imageArray;
}
@end
@implementation TableViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSMutableArray *removeAllData = [NSMutableArray arrayWithObjects:imageArray,labelArray,nil];
[removeAllData removeAllObjects];
[self.tableView setDelegate:self];
[self.tableView setDataSource:self];
labelArray = [[NSMutableArray alloc]init];
imageArray = [[NSMutableArray alloc]init];
NSString *strURL = @"https://itunes.apple.com/tr/rss/newapplications/limit=25/json";
NSURL *url = [NSURL URLWithString:strURL];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
connection = [NSURLConnection connectionWithRequest:request delegate:self];
if (connection) {
webData = [[NSMutableData alloc]init];
}
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
[webData setLength:0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
[webData appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
NSLog(@"Error");
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection{
NSDictionary *allDataDictionary = [NSJSONSerialization JSONObjectWithData:webData options:kNilOptions error:nil];
NSDictionary *allFeedDictionary = [allDataDictionary objectForKey:@"feed"];
NSArray *arrayOfEntry = [allFeedDictionary objectForKey:@"entry"];
for (NSDictionary *diction in arrayOfEntry) {
NSDictionary *title = [diction objectForKey:@"title"];
NSDictionary *imImage = [diction objectForKey:@"im:image"];
for (NSDictionary *imageDict in imImage) {
NSDictionary *imageLabel = [imageDict objectForKey:@"label"];
[imageArray addObject:imageLabel];
}
NSString *label = [title objectForKey:@"label"];
[labelArray addObject:label];
}
[self.tableView reloadData];
NSLog(@"%@",[imageArray objectAtIndex:0]);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return labelArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
//NSData *imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString: [imageArray objectAtIndex:indexPath.row]]];
NSData *imageData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:[imageArray objectAtIndex:indexPath.row]]];
UIImage *image = [[UIImage alloc] initWithData:imageData];
cell.textLabel.text = [labelArray objectAtIndex:indexPath.row];
cell.imageView.image = image;
return cell;
}[/code]
İzlemiş olduğum yöntemin doğru olup olmadığını bilmiyorum ama Title' ları tableView ' a çekiyorum fakat işler resimleri cell' e atmaya geldiğinde karışıyor. Burada yer alan resimlerin her birisi farklı 3 boyutta sıralanıyor yani tutarsızlık oluyor. Sorum tam olarak şöyle oradaki her bir nesneye ait tek bir resim dosyasının linkini nasıl alabilirim? Yardımlarınız için teşekkürler...
jSon Data Adresi :
jSon Parser Linki: