NSJSONSerialization not updating data

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];
});

Answers


How do you set "myURL", only in viewDidLoad? After a while if the OS calls viewDidUnload and you run the app again, viewDidLoad is called and myURL is set again. If thats the case you should set myURL every time you call getInfo.


Need Your Help

Zip an epub using a batch file and 7zip

batch-file 7zip epub3

I created this batch file to compress my epub files into an epub.

Trouble with filewriter overwriting files instead of appending to the end

java file filewriter

OK, I'm having some trouble writing multiple lines to a text file.