Playlist Generator
1.0
|
00001 // 00002 // ReadPlaylistSuggestions.m 00003 // Playlist2 00004 // 00005 // Created by Max Woolf on 16/12/2011. 00006 // Copyright (c) 2011 __MyCompanyName__. All rights reserved. 00007 // 00008 00009 #import "ReadPlaylistSuggestions.h" 00010 00011 @implementation ReadPlaylistSuggestions 00012 00013 -(id)initWithJsonData:(NSData *) data 00014 { 00015 jsonData = data; 00016 jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; 00017 parser = [[SBJsonParser alloc] init]; 00018 NSError *error = nil; 00019 NSLog(@"%@", jsonString); 00020 00021 //jsonRootDictionary holds all json data as parsed dictionary now 00022 jsonRootDictionary = [parser objectWithString:jsonString error:&error]; 00023 00024 //Return object 00025 self = [super init]; 00026 return self; 00027 } 00028 00029 -(int)calculateNumberOfSongs 00030 { 00031 return [[self getSongsArray] count]; 00032 } 00033 00034 -(NSArray *)getSongsArray 00035 { 00036 NSDictionary *response = [jsonRootDictionary objectForKey:@"response"]; 00037 return [response objectForKey:@"songs"]; 00038 } 00039 00040 -(NSMutableArray *)getArtistList 00041 { 00042 NSMutableArray *artistList = [[NSMutableArray alloc] initWithCapacity:[self calculateNumberOfSongs]]; 00043 00044 //For each element in the array, add the artist 00045 for(int x = 0; x < [self calculateNumberOfSongs]; x++) 00046 { 00047 NSDictionary *currentSong = [[self getSongsArray] objectAtIndex:x]; 00048 [artistList addObject:[currentSong objectForKey:@"artist_name"]]; 00049 } 00050 return artistList; 00051 } 00052 00053 -(NSMutableArray *)getTrackList 00054 { 00055 NSMutableArray *trackList = [[NSMutableArray alloc] initWithCapacity:[self calculateNumberOfSongs]]; 00056 00057 //For each element in the array, add the artist 00058 for(int x = 0; x < [self calculateNumberOfSongs]; x++) 00059 { 00060 NSDictionary *currentSong = [[self getSongsArray] objectAtIndex:x]; 00061 [trackList addObject:[currentSong objectForKey:@"title"]]; 00062 } 00063 return trackList; 00064 } 00065 @end