I am trying to parse JSON with iOS5's NSJSONSerialization. This code CORRECTLY parse the data I wanted for the first time, BUT THEN THE DATA JUST STAYED THE SAME. The JSON on the URL already changed, but the code kept giving me the first data it parsed, which is now incorrect. No matter how many times I "build and run", it keeps giving me the same thing.
When I copied the code to the new project, it works, again, for the first time, and then does the same thing.
I have no idea where the problem is, maybe cache?
Thanks for you help!!!
- (void)fetchedData:(NSData *)responseData {
NSError* error;
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseData
options:kNilOptions
error:&error];
NSArray* allDepartures = [json objectForKey:@"departures"];
NSLog(@"departures: %@", allDepartures);
NSDictionary* stops = [allDepartures objectAtIndex:0];
NSNumber* time = [stops objectForKey:@"expected_mins"];
NSString* name = [stops objectForKey:@"headsign"];
nameLabel.text = [NSString stringWithFormat:@"%@",name];
timeLabel.text = [NSString stringWithFormat:@"%i",[time intValue]];
}
- (IBAction)getInfo:(id)sender {
dispatch_async(kBgQueue, ^{
NSData* data = [NSData dataWithContentsOfURL: myURL];
[self performSelectorOnMainThread:@selector(fetchedData:)
withObject:data waitUntilDone:YES];
});