title: NSURLConnection and JSON Data
body: <p>I am stuck with something crazy. I used <code>ASIHTTPRequest</code> to receive my data from a web service and everything worked fine. I switched to using a <code>NSURLConnection</code> and I am receiving the same data and parsing it the same way but my code won't recognize the data with the <code>NSURLConnection</code>.</p>
  
  <p>Here is the data I am receiving (from <code>NSLog</code>)</p>
  
  <pre><code>Did receive data: {"d":"[{\"id\":1.0,\"Category\":1,\"hPlan\":0.0,\"Tip\":\"It takes 3500   
  calories to gain a pound. If you want to lose a pound per week, reduce your calorie
  intake by 250 calories and incorporate daily physical activity that will burn 250   
  calories.\",\"TipDate\":\"2012-05-12T00:00:00\",\"TimeStamp\":\"AAAAAAAAB9I=\"}]"}
  
  
  2012-06-06 09:42:11.809 StaticTable[27488:f803] Jsson Array: 0  
  2012-06-06 09:42:11.809 StaticTable[27488:f803] Jsson Array: (null)
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>#import "UYLFirstViewController.h"
  #import "MBProgressHUD.h" 
  #import "JSON.h"
  
  @interface UYLFirstViewController ()
  
  @end
  
  @implementation UYLFirstViewController
  
  #pragma mark -
  #pragma mark === UIViewController ===
  #pragma mark -
  
  @synthesize MessageField;
  @synthesize jsonArray = _jsonArray;
  @synthesize TipLabelField;
  
  
  - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  {
  self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  if (self) {
      self.title = NSLocalizedString(@"Tickle!", @"Tickle!");
       self.tabBarItem.image = [UIImage imageNamed:@"heart_plus"];
  
      [self GetTipOfDay];
  
  }
  return self;
  }
  
  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  {
      return YES;
  }
  -(BOOL)GetTipOfDay{
  
  NSDate *date = [NSDate date];
  
  NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];
  [dateFormat setDateFormat:@"EEEE MMMM d, YYYY"];
  NSString *dateString = [dateFormat stringFromDate:date];
  
  
  NSString *yourOriginalString = @"Tip of the Day for ";
  
  yourOriginalString = [yourOriginalString stringByAppendingString:dateString];
  TipLabelField.text = yourOriginalString;
  
  
  NSURL *url = [NSURL URLWithString:@"http://www.mysite.com/api/GetHealth.asmx/getTipOfDay"];
  
  
  NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
  [request setHTTPMethod:@"GET"];
  [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
  [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
  
  [NSURLConnection connectionWithRequest:request delegate:self];
  
  
  
  // Clear text field
  MessageField.text = @"";
  
  // Start hud
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.labelText = @"Gathering Tip of the Day...";
  
  return TRUE;
  
  }
  
  - (void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
  {
  
  [MBProgressHUD hideHUDForView:self.view animated:YES];
  
  
  NSLog(@"Did receive data: %@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
  
  
  NSDictionary *responseDict = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] JSONValue];
  
  NSString *jsonResponse = [responseDict objectForKey:@"d"];
  
  self.jsonArray = [jsonResponse JSONValue];
  
  
  NSLog(@"Jsson Array: %d", [jsonArray count]);
  NSLog(@"Jsson Array: %@", jsonArray);
  
  
  NSEnumerator *myEnumerator;
  myEnumerator = [jsonArray objectEnumerator];
  int i;
  i=0;
  id myObject;
  
  while (myObject = [myEnumerator nextObject])
  {
      NSDictionary *itemAtIndex = (NSDictionary *)[self.jsonArray objectAtIndex:i];
  
      NSLog(@"Checking for games");
  
      NSString *myCheck = [itemAtIndex objectForKey:@"FName"];
  
      if ([myCheck length] != 0)
      {
          // NSLog(myCheck);
          MessageField.text = myCheck;
      }
  }
  
  } 
  
  
  
  - (void)viewDidUnload {
  [self setMessageField:nil];
  [self setTipLabelField:nil];
  [super viewDidUnload];
  }
  @end
  
  
  #import &lt;UIKit/UIKit.h&gt;
  
  @interface UYLFirstViewController : UIViewController{
    NSMutableArray *jsonArray;  
  }
  @property (weak, nonatomic) IBOutlet UILabel *MessageField;
  @property (weak, nonatomic) NSMutableArray *jsonArray;
  @property (weak, nonatomic) IBOutlet UILabel *TipLabelField;
  
  -(BOOL)GetTipOfDay;
  
  
  @end
  </code></pre>