JSON を使用して、Rails アプリから iOS アプリへのオブジェクトを解析しています。投稿ごとにサムネイルを表示できるようにしたいのですが、画像は配列内にネストされており、投稿ごとに多くの画像があり、各画像にはサムネイルと完全な画像があるだけではありません。各投稿の FIRST 画像のサムネイルを表示するにはどうすればよいですか?
ありがとう。
JSON
upcoming_releases: [
{
id: 2,
release_name: "Lebron X Low",
release_price: "165",
release_colorway: "Raspberry-Red/Blueprint-Court",
release_date: "2013-09-07T00:00:00.000Z",
url: "http://obscure-lake-7450.herokuapp.com/upcoming/2",
images: [
{
image_file: {
image_file: {
url: "https://s3.amazonaws.com/soleresource/uploads/releases/nike-lebron-x-low-raspberry.jpg",
thumb: {
url: "https://s3.amazonaws.com/soleresource/uploads/releases/thumb_nike-lebron-x-low-raspberry.jpg"
}
}
}
},
{
image_file: {
image_file: {
url: "https://s3.amazonaws.com/soleresource/uploads/releases/nike-lebron-x-low-raspberry.jpg-2",
thumb: {
url: "https://s3.amazonaws.com/soleresource/uploads/releases/thumb_nike-lebron-x-low-raspberry-2.jpg"
}
}
}
},
{
]
}、
私のビューコントローラー
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *upcomingReleaseURL = [NSURL URLWithString:@"http://obscure-lake-7450.herokuapp.com/upcoming.json"];
NSData *jsonData = [NSData dataWithContentsOfURL:upcomingReleaseURL];
NSError *error = nil;
NSDictionary *dataDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
self.upcomingReleases = [NSMutableArray array];
NSArray *upcomingReleasesArray = [dataDictionary objectForKey:@"upcoming_releases"];
for (NSDictionary *upcomingReleaseDictionary in upcomingReleasesArray) {
UpcomingRelease *upcomingRelease = [UpcomingRelease upcomingReleaseWithName:[upcomingReleaseDictionary objectForKey:@"release_name"]];
upcomingRelease.release_price = [upcomingReleaseDictionary objectForKey:@"release_price"];
upcomingRelease.release_colorway = [upcomingReleaseDictionary objectForKey:@"release_colorway"];
upcomingRelease.release_date = [upcomingReleaseDictionary objectForKey:@"release_date"];
upcomingRelease.url = [upcomingReleaseDictionary valueForKeyPath:@"url"];
[self.upcomingReleases addObject:upcomingRelease];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
UpcomingRelease *upcomingRelease = [self.upcomingReleases objectAtIndex:indexPath.row];
if ( [upcomingRelease.url isKindOfClass:[NSString class]]) {
NSData *imageData = [NSData dataWithContentsOfURL:upcomingRelease.thumbURL];
UIImage *image = [UIImage imageWithData:imageData];
cell.imageView.image = image;
}
else {
// cell.imageView.image = [UIImage imageNamed:@"cover.png"];
}
cell.textLabel.text = upcomingRelease.release_name;
cell.detailTextLabel.text = [NSString stringWithFormat:@"$%@", upcomingRelease.release_price];
return cell;
}
UpcomingRelease.h
@property (nonatomic, strong) NSString *url;
- (NSURL *) thumbURL;