Wednesday 18 January 2012

JSON Parsing Demo


- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    NSLog(@"\n\n View of Msg List");
    dicRequest =[[NSMutableArray alloc]init];
    self.navigationItem.title=@"Messages";
    self.navigationController.navigationBarHidden = FALSE;
    NSURL *url = [NSURL URLWithString:@"http://212.68.63.233/secure/mehphoze/listMessages"];
    
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
    [request setPostValue:uid forKey:@"user_id"];
    
    [request setDelegate:self];
    
    [request startAsynchronous];
    isdelete = @"No";
    [self.tableView setFrame:CGRectMake(0, 38, 320,384)];
}
- (void)requestFinished:(ASIHTTPRequest *)request {
        // Use when fetching text data
        NSString *responseString = [request responseString];
        NSLog(@"\n\n>>>>......Response String >>> %@",responseString);
        // Use when fetching binary data
        //    NSData *responseData = [request responseData];
        
        if(responseString){
            SBJSON *json = [[SBJSON alloc] init];
            NSError *error = nil;
            id j = [json objectWithString:responseString error:&error];
            if ([j isKindOfClass:[NSMutableArray class]]) {
                NSLog(@"\n\n.......This is Mutable Array");
            }
            dicRequest = [json objectWithString:responseString error:&error];
            [dicRequest retain];
            [json release];
            NSLog(@"\n\n......>>> Dict : %@",dicRequest);
            
        }
    
    [appdelegate hideLoadingView];
    [self.tableView reloadData];
}

- (void)requestFailed:(ASIHTTPRequest *)request {
    //NSError *error = [request error];
}

No comments:

Post a Comment