Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 1.13 KB  |  hits: 14  |  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. Send JSON string in iOS and get proper response
  2. -(void)requestProjects
  3. {
  4.     responseData=[[NSMutableData alloc] init];
  5.     responseArray=[[NSMutableArray alloc] init];
  6.     NSURLRequest *request = [NSURLRequest requestWithURL:
  7.                              [NSURL URLWithString:@"http://search.twitter.com/search.json?q=mobtuts&rpp=5"]];
  8.     NSURLConnection *connection=[[NSURLConnection alloc] initWithRequest:request delegate:self];
  9.     [connection start];
  10. }
  11.  
  12. #pragma mark NSURLConnection delegate methods
  13. - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
  14.     [responseData setLength:0];
  15. }
  16.  
  17. - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
  18.     [responseData appendData:data];
  19. }
  20.  
  21. - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
  22.     NSLog(@"Connection failed!");
  23. }
  24.  
  25. - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
  26.  
  27.     NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
  28.  
  29.  
  30.     NSDictionary *results = [responseString JSONValue];
  31.     NSLog(@"Response: %@", results);
  32. }