I am using a REST based web service to get data. No matter what the structure of the JSON document, the NSDictionary gets populated the same way. I want the sorting preserved as the web service returns.
Here is my code:
-(void) getData
{
NSURL *url = [NSURL URLWithString:@"http://somewebservice"];
__block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setCompletionBlock:^{
// Use when fetching text data
NSString *responseString = [request responseString];
NSDictionary *resultsDictionary = [responseString objectFromJSONString];
[jokesArray release];
jokesArray = [resultsDictionary allValues]; //always has the same order.
[jokesArray retain];
[self.tableView reloadData];
// Use when fetching binary data
// NSData *responseData = [request responseData];
}];
[request setFailedBlock:^{
NSError *error = [request error];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"An error occured"
message:[error description]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}];
[request startAsynchronous];
}