// JSON EXAMPLE
.H FILE
NSMutableArray *arrRespone;
NSMutableDictionary *resultsDictionary;
.M FILE
define kBgQueue dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) //1
// how can print array json values into uitableview in iphone
import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize tableView1;
{
arrRespone=[NSMutableArray new];
practice_ArrayForDisplayingEx=[[NSArray alloc]initWithObjects:@"bhupi",@"bhupi",@"bhupi",@"bhupi",nil];
dispatch_async(kBgQueue, ^
{
NSData* dataURL = [NSData dataWithContentsOfURL: kLatestKivaLoansURL];
[self performSelectorOnMainThread:@selector(fetchedData:) withObject:dataURL waitUntilDone:YES];
});
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
(void)fetchedData:(NSData *)responseData
{
NSError *error;
resultsDictionary = [NSJSONSerialization JSONObjectWithData:responseData //1
options:kNilOptions
error:&error];
NSDictionary *arrDetails=[[resultsDictionary objectForKey:@"menu"] objectAtIndex:0] ;
NSDictionary *genr=[[arrDetails valueForKey:@"categories"] objectAtIndex:0];
NSLog(@"array detailsarray ====>%@",arrDetails);
NSLog( @"genreee arrray==%@",genr);
//NSLog(@"genrvalueeee -----%@",[genr valueForKey:@"genre"]);
NSLog(@"counttttt===%d",[[genr valueForKey:@"genre" ] count]);
NSLog(@"genre objectatindex==%@",[genr valueForKey:@"cliptype"]);
for (int i=0;i<[[genr valueForKey:@"genre" ] count];i++)
{
NSDictionary *strDetails=[[genr valueForKey:@"genre"] objectAtIndex:i];
NSString *str=[strDetails valueForKey:@"gname"];
NSLog(@"First string details===>%@",str);
[arrRespone addObject:str];
NSLog(@"response ====>%@",arrRespone);
}
[tableView1 reloadData];
}
pragma mark Table view methods
(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
NSLog(@"numberOfSectionsInTableView");
return 1;
}
(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 45;
NSLog(@"heightForRowAtIndexPath");
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSLog(@"numberOfRowsInSection");
return [arrRespone count];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"inside tableview");
static NSString *CellIdentifier = @"TableCell";
//TableCell *cell = (TableCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier];
}
// cell.textLabel.text=[arrRespone objectAtIndex:indexPath.row];
NSLog(@"cellvalue:%@",cell.textLabel.text);
NSLog(@"inside numberofRowsInsection");
// Configure the cell...
cell.textLabel.text = [arrRespone objectAtIndex:indexPath.row];
return cell;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end