I am new to IOS i need to display json fetched data into uitableview my json pattern look like this.
{"output":[{"id":{"php":"1"},"name":{"php":"ramkumar"},"image":{"1":"http:\/\/www.easyteach.gr\/users\/tutor\/1432636961.jpg"}},{"id":{"php":"2"},"name":{"php":"rakshi"},"image":{"2":"http:\/\/www.easyteach.gr\/users\/tutor\/1440371842.jpg"}},{"id":{"android":"1"},"name":{"android":"Vijayan"},"image":{"3":"http:\/\/www.easyteach.gr\/users\/tutor\/1432636961.jpg"}},{"id":{"android":"2"},"name":{"android":"vishali"},"image":{"4":"http:\/\/www.easyteach.gr\/users\/tutor\/1440371842.jpg"}},{"id":{"android":"3"},"name":{"android":"Niranjan"},"image":{"5":"http:\/\/www.easyteach.gr\/users\/tutor\/1432636961.jpg"}}]}
viewdidload coding:
i created json url into array format in viewdidload itself and displayed successfully in nslog but in tableview it can failed.
if(data){
NSError *error;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options: kNilOptions error:&error];
NSLog(@"%@",json);
nameArray = [json valueForKeyPath:@"output.name"];
php = [nameArray valueForKey:@"php"];
}
[_tabledata reloadData];
Tableview delegates:
-(NSInteger)numberOfSectionsInTableView:(UITableView *) tableView{
return 1;
}
-(NSInteger)tableView:(UITableView *) tableView numberOfRowsInSection:(NSInteger)section{
return [php count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
TableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"table" forIndexPath:indexPath];
cell.iteam.text=[php objectAtIndex:indexPath.row];
return cell;
}
-(void)tableView: (UITableView *) tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{
}