Here is the code I am using to create poll data from a json framework. However every time I launch the app it crashes. Any Advice?
-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
self.responseData = nil;
NSArray *latestEvent = [(NSDictionary*)[responseString JSONValue] objectForKey:@"Events"];
[responseString release];
//Choose event
NSDictionary *flashMob = [latestEvent objectAtIndex:0];
//Fetch the Data
NSString *name = [flashMob objectForKey:@"event"];
NSDate *eDate = [flashMob objectForKey:@"date"];
NSString *location = [flashMob objectForKey:@"location"];
NSString *danceVid = [flashMob objectForKey:@"dancevideo"];
//Set the text to the label
label.text = [NSString stringWithFormat:@"Next Flash Mob is: %@, on %@, near %@, with Dance: %@", name, eDate, location, danceVid];
}
And the Json is:
{ "Events":[{"id":0001,"event":"Party Rock Anthem Flash Mob","date":"12/18/2011",
"dancevideo":"http://www.youtube.com/watch?v=dP2ddTuMKIg","Location":"Flatirons Crossing, Broomfield, CO"}]
}
Edit I am also including the viewDidLoad method unless the call might be failing.
- (void)viewDidLoad
{
[super viewDidLoad];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.corliosity.com/denverflash.json"]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
responseData = [[NSMutableData data] retain];
// Do any additional setup after loading the view from its nib.
}
Try this code below
Now you should see Events key inside JSONDictionary, the corresponding object should be an array of dictionary.
Process it in the way you prefer.