This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jul 25th, 2011  |  syntax: Objective C  |  size: 1.25 KB  |  views: 75  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }
clone this paste RAW Paste Data