You have to make an object of NSURLConnection
instead of NSData
and in response you will be get data in NSURLConnection
's delegate method.
NSURLConnection *connection=[[NSURLConnection alloc]initWithRequest:request delegate:self];
#pragma NSURLConnection Delegate Methods
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
//buffer is the object Of NSMutableData and it is global,so declare it in .h file
buffer = [NSMutableData data];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[buffer appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
//Here You will get the whole data
NSArray *array = [NSJSONSerialization JSONObjectWithData:buffer options:0 error:&jsonParsingError];
//And you can used this array
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
//if any error occurs..
}