2016-03-15 55 views
0
  { 
       "COMPETITION_CODE":"UCC0000003", 
       "MATCH_CODE":"DMSC1160026829B543400022", 
       "MATCH_DATE":"1/18/2016 12:00:00 AM", 
       "A_TEAMNAME":"UTTAR PRADESH", 
       "B_TEAMNAME":"DELHI", 
       "A_TEAMSHORTNAME":"UPCA", 
       "B_TEAMSHORTNAME":"DHL", 
       "BATTING_TEAMNAME":"UTTAR PRADESH", 
       "MATCH_TYPE":"MSC116", 
       "HOME_TEAM":"UTTAR PRADESH", 
       "FIRSTINNINGS_SHORTNAME":"DHL", 
       "FIRSTINNINGS_SCORE":"158/6", 
       "FIRSTINNINGS_TOTAL":"158", 
       "FIRST_INNINGSWICKET":"6", 
       "FIRST_INNINGSOVERS":"20.0", 
       "SECOND_INNINGSSHORTNAME":"UPCA", 
       "SECOND_INNINGSSCORE":"159/7", 
       "SECOND_INNINGSTOTAL":"159", 
       "SECOND_INNINGSWICKET":"7", 
       "SECOND_INNINGSOVERS":null, 
       "THIRD_INNINGSSHORTNAME":"", 
       "THIRD_INNINGSSCORE":"0/0", 
       "THIRD_INNINGSTOTAL":"0", 
       "THIRD_INNINGSWICKET":"0", 
       "THIRD_INNINGSOVERS":"", 
       "FOURTH_INNINGSSHORTNAME":"", 
       "FOURTH_INNINGSSCORE":"0/0", 
       "FOURTH_INNINGSTOTAL":"0", 
       "FOURTH_INNINGSWICKET":"0", 
       "FOURTH_INNINGSOVERS":"", 
       "FIRST_INNINGSLOGO":null, 
       "SECOND_INNINGSLOGO":null, 
       "RUN_RATE":"8.1", 
       "REQUIREDRUN_RATE":"0.0", 
       "MATCH_RESULT":"Won by 3 Wickets", 
       "Player_TeamList":[ 
        { 
         "PLAYER_NAME":"PRAVEEN KUMAR", 
         "PLAYER_ROLE":"Bowler", 
         "TEAM_NAME":"UTTAR PRADESH", 
         "TEAM_CODE":"TEA0000001", 
         "PLAYER_ORDER":"1" 
        }, 
        { 
         "PLAYER_NAME":"AKSHDEEP NATH", 
         "PLAYER_ROLE":"Batsman", 
         "TEAM_NAME":"UTTAR PRADESH", 
         "TEAM_CODE":"TEA0000001", 
         "PLAYER_ORDER":"1" 
        }, 
        { 
         "PLAYER_NAME":"AMIT MISHRA", 
         "PLAYER_ROLE":"Bowler", 
         "TEAM_NAME":"UTTAR PRADESH", 
         "TEAM_CODE":"TEA0000001", 
         "PLAYER_ORDER":"1" 
        }, 
        { 
         "PLAYER_NAME":"PIYUSH CHAWLA", 
         "PLAYER_ROLE":"All Rounder", 
         "TEAM_NAME":"UTTAR PRADESH", 
         "TEAM_CODE":"TEA0000001", 
         "PLAYER_ORDER":"1" 
        }, 
        { 
         "PLAYER_NAME":"ANKIT RAJPOOT", 
         "PLAYER_ROLE":"Bowler", 
         "TEAM_NAME":"UTTAR PRADESH", 
         "TEAM_CODE":"TEA0000001", 
         "PLAYER_ORDER":"1" 
        }] 
       } 

我嘗試瞭解析填充數據serviceResponse得到響應值,但需要填充在tableview中索引路徑數組和字典值如何解析數據...在tableview中

任何一個請幫我解決這個問題提前

NSURL *url = [NSURL URLWithString:[baseURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 
NSURLRequest *request = [NSURLRequest requestWithURL:url]; 
    NSURLResponse *response; 
NSError *error; 
NSData *responseData =[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; 
NSDictionary *serviceResponse=[NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error]; 

感謝

+0

你可以發佈你所得到的實際響應,你必須提供響應似乎只有一個對象,它是否像你必須在一個單元格中顯示數據或解釋什麼?編輯抱歉,我沒有正確查看問題,您已經提供了完整的答覆。 –

+0

所以,你必須顯示 「PLAYER_NAME」: 「PIYUSH喬拉」, 「PLAYER_ROLE」: 「多面手」, 「TEAM_NAME」: 「北方邦」, 「TEAM_CODE」: 「TEA0000001」, 「PLAYER_ORDER」:」 1「在細胞上? –

+0

s Bharat Modi我必須通過單元格上的所有值不僅數組值 – fathima

回答

0

你的問題是不明確的,從您提供的響應,似乎你必須顯示如下ATTRIB上的tableView細胞茨,

{ 
    "PLAYER_NAME":"PRAVEEN KUMAR", 
    "PLAYER_ROLE":"Bowler", 
    "TEAM_NAME":"UTTAR PRADESH", 
    "TEAM_CODE":"TEA0000001", 
    "PLAYER_ORDER":"1" 
} 

你應該分析數據作爲

NSDictionary *serviceResponse=[NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error]; 

NSArray *arrayOfPlayer_TeamList = serviceResponse[@"Player_TeamList"]; 

而且一旦你解析響應,重新加載的tableView的主線程。

編輯/更新:

如果你有使用整個響應,然後就解析在serviceResponse字典中的響應,你已經被解析,使字典全球和你的cellForRowAtIndexPath裏面:

  1. 當你要顯示的比賽日期,

    NSString *matchDate = serviceResponse[@"MATCH_DATE"]; 
    
  2. 和W母雞你必須顯示「PLAYER_NAME」這將是對每個小區不同,

    NSString *playerName = serviceResponse[@"Player_TeamList"][indexPath.row][@"PLAYER_NAME"]; 
    

希望這會幫助你。

EDIT2/UPDATE2:

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 

    return [_dictTeamData[@"Player_TeamList"] count]; 
} 

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *cellIdentifier = @"cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 

    //Team Name & Batting Team Name are outside Player_TeamList 

    //Team Name 
    UILabel *teamName = (UILabel*) [cell viewWithTag:10]; 
    teamName.text = _dictTeamData[@"A_TEAMNAME"]; 

    //Batting Team Name 
    UILabel *battingTeamName = (UILabel*) [cell viewWithTag:20]; 
    battingTeamName.text = _dictTeamData[@"BATTING_TEAMNAME"]; 


    //Player Name & Player Role inside Player_TeamList 
    //Player Name 
    UILabel *playerName = (UILabel*) [cell viewWithTag:30]; 
    playerName.text = _dictTeamData[@"Player_TeamList"][indexPath.row][@"PLAYER_NAME"]; 

    //Player Role 
    UILabel *playerRole = (UILabel*) [cell viewWithTag:40]; 
    playerRole.text = _dictTeamData[@"Player_TeamList"][indexPath.row][@"PLAYER_ROLE"]; 
    return cell; 
} 

,其結果是:

enter image description here