
Untitled
By: a guest on
May 7th, 2012 | syntax:
None | size: 1.13 KB | hits: 14 | expires: Never
Send JSON string in iOS and get proper response
-(void)requestProjects
{
responseData=[[NSMutableData alloc] init];
responseArray=[[NSMutableArray alloc] init];
NSURLRequest *request = [NSURLRequest requestWithURL:
[NSURL URLWithString:@"http://search.twitter.com/search.json?q=mobtuts&rpp=5"]];
NSURLConnection *connection=[[NSURLConnection alloc] initWithRequest:request delegate:self];
[connection start];
}
#pragma mark NSURLConnection delegate methods
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[responseData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[responseData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
NSLog(@"Connection failed!");
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSDictionary *results = [responseString JSONValue];
NSLog(@"Response: %@", results);
}