Advertisement
Guest User

Untitled

a guest
Jul 25th, 2011
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - (void)loadDataFromWeb {
  2.     NSLog(@"loadDataFromWeb: start");
  3.    
  4.     // Check for internet connection and alert user if there's none
  5.     NetworkReach = [[InternetReachability alloc] init];
  6.     if (![NetworkReach checkInternet])
  7.         [NetworkReach internetAlert:@"Eatstrong" message:@"Der er ikke oprettet forbindelse til et netværk." cancelButton:@"OK"];
  8.    
  9.     // Setup parameters
  10.     NSURL *url           = [NSURL URLWithString:@"http://www.eatstrong.dk/iphone_recipeList.php"];
  11.     NSString *jsonreturn = [[NSString alloc] initWithContentsOfURL:url];
  12.     NSData *jsonData     = [jsonreturn dataUsingEncoding:NSUTF32BigEndianStringEncoding];
  13.     NSError *error       = nil;
  14.    
  15.     // Create dictionaries
  16.     NSDictionary *dict = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error]; // Recipes
  17.    
  18.     // Set recipes
  19.     if (dict)
  20.     {
  21.         self.recipes = dict;
  22.         NSLog(@"Recipes added to dictionary");
  23.     }
  24.     else
  25.     {
  26.         NSLog(@"Error during JSON deserialization. Probably no internet conncetion.");
  27.     }
  28.    
  29.     // Set keys
  30.     NSArray *array = [[recipes allKeys] sortedArrayUsingSelector:@selector(compare:)];
  31.     self.keys = array;
  32.    
  33.     NSLog(@"loadDataFromWeb: done");
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement