Wednesday, 22 January 2014

JSON

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
    [mdata  setLength:0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
    [mdata appendData:data];
}

-(void)connectionDidFinishLoading:(NSURLConnection *)connection{
    NSError *err;
    NSString *str=[[NSJSONSerialization JSONObjectWithData:mdata options:-1 error:&err] description];
    //NSLog(@"%@",err.localizedDescription);
  t1.text=str;
 NSLog(@"Succeeded! Received %d bytes of data",[mData length]);//Bytes Received
   NSLog(@"The received data are%@",mData); 
}
- (IBAction)click:(id)sender {
    NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://www.googleapis.com/youtube/v3/videos"]];
    
    NSURLConnection *connection=[NSURLConnection connectionWithRequest:request delegate:self];
    if(connection)
    {
        mdata=[NSMutableData data];
        [connection start];
    }


}

No comments:

Post a Comment