私はobjective-cが初めてで、json配列を解析してテーブルセルに表示しているiosアプリに取り組んでいます。1 つのセルに 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";
}
ここでは、単一セル内の 2 つの異なる配列から戦闘機の名前を表示したいと思います。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];
}