我是 Objective-c 的新手,正在开发 ios 应用程序,我正在解析 json 数组并将其显示在表格单元格中。我有一个问题,我想在单个单元格中显示 2 个 json 数组值,但我没有正确获取这些值,这是我的 json 数组
{
"event_id" = 7;
"fighter_id" = 26;
"fighters_name" = "Kaushik Sen";
"fighters_photo" = "Kaushik.jpg";
"match_id" = 28;
"match_type" = Bantamweight;
"profile_link" = "link";
}
{
"event_id" = 7;
"fighter_id" = 21;
"fighters_name" = "Kultar Singh Gill";
"fighters_photo" = "Kultar.jpg";
"match_id" = 27;
"match_type" = "Welterweights Main Event";
"profile_link" = "link";
}
在这里,我想在单个单元格中显示来自两个不同数组的战斗机名称,例如。kaushik sen vs kultar singh gill,但我在牢房里得到了备用球员的名字。这是我的目标 c 代码。
- (void)viewDidLoad
{
[super viewDidLoad];
[self MatchList];
}
-(void)MatchList {
NSURLRequest *request=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://example.com/appleapp/eventDetails.php"]];
NSError *error;
//code to execute php code
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error];
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
NSMutableArray *matchListArray = [[NSMutableArray alloc]init];
matchListArray = [json objectForKey:@"products"];
arrayOfFighterName=[[NSMutableArray alloc] init];
arrOfMatchId = [[NSMutableArray alloc] init];
for( int i = 0; i<[matchListArray count]; i++){
// NSLog(@"%@", [matchListArray objectAtIndex:i]);
arrayOfFighterName[i]=[[matchListArray objectAtIndex:i] objectForKey:@"fighters_name"];
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [arrayOfFighterName count]/2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
cell = (MyFighterCell *)[tableview dequeueReusableCellWithIdentifier:kCellIdentifier];
select = indexPath.row;
if(cell == nil){
cell = [[[MyFighterCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellIdentifier] autorelease];
[cellOwner loadMyNibFile:kCellIdentifier];
cell = (MyFighterCell *)cellOwner.cell;
}
cell.lblPlayer1.text = [arrayOfFighterName objectAtIndex:indexPath.row];
cell.lblPlayer2.text = [arrayOfFighterName objectAtIndex:indexPath.row +1];
}