Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7175047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:11:51+00:00 2026-05-28T16:11:51+00:00

I have been trying for days to figure out how to parse this JSON

  • 0

I have been trying for days to figure out how to parse this JSON to a sectioned UITable but I am not successful, I’ve only been able to figure out how to get the section name, but failed to get each section row count and data for each row in each section.

Since the transportation group may vary from time to time and their name may change, so I guess I need to use allKeys to find out each section title 1st.

Please help and points me to the right direction to extract the data for a sectioned UITable, Thank you.

{
   "transport" : {
  "public" : [
     {
        "transport_id" : "2",
        "transport_name" : "Ferry"
     },
     {
        "transport_id" : "3",
        "transport_name" : "Bus"
     },
     {
        "transport_id" : "4",
        "transport_name" : "Taxi"
     },
     {
        "transport_id" : "5",
        "transport_name" : "Tram"
     }
  ],
  "Private" : [
     {
        "transport_id" : "11",
        "transport_name" : "Bicycle"
     },
     {
        "transport_id" : "12",
        "transport_name" : "Private Car"
     }
  ],
  "Misc" : [
     {
        "transport_id" : "6",
        "transport_name" : "By Foot"
     },
     {
        "transport_id" : "7",
        "transport_name" : "Helicopter"
     },
     {
        "transport_id" : "8",
        "transport_name" : "Yatch"
     }
  ]
   }
}  



NSDictionary *results = [jsonString JSONValue];

NSDictionary *all = [results objectForKey:@"transport"];
NSArray *allKeys = [all allKeys];

NSArray *transports = [results objectForKey:@"transport"];
for (NSDictionary *transport in transports)
{
    [transportSectionTitle addObject:(transport)];
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [transportSectionTitle count];
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:11:52+00:00Added an answer on May 28, 2026 at 4:11 pm

    The easiest solution to explain is to use the all dictionary as your datasource.

    NSDictionary *results = [jsonString JSONValue];
    
    NSDictionary *all = [results objectForKey:@"transport"];
    
    // self.datasource would be a NSDictionary retained property
    self.datasource = all;
    

    Then to get the number of sections you could do :

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
        return [self.datasource count]; // You can use count on a NSDictionary
    }
    

    To get the title of the sections:

    - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    
        NSString *title = [[self.datasource allKeys] objectAtIndex:section];
    
        return title;
    }
    

    To get the number of rows in each section:

    - (NSInteger)tableView:(UITableView *)favTableView numberOfRowsInSection:(NSInteger)section {
    
        // Get the all the transports
        NSArray *allTransports = [self.datasource allValues];
    
        // Get the array of transports for the wanted section
        NSArray *sectionTransports = [allTransports objectAtIndex:section];
    
        return [sectionTransports count];
    }
    

    Then to get the rows :

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
         static NSString *CellIdentifier = @"Cell";
    
         UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
         if (cell == nil) {
             cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
         }
    
         // Get the all the transports
         NSArray *allTransports = [self.datasource allValues];
    
         // Get the array of transports for the wanted section
         NSArray *sectionTransports = [allTransports objectAtIndex:indexPath.section];
    
         // Then get the transport for the row
         NSDictionary *transport = [sectionTransports objectAtIndex:indexPath.row];
    
         // Now you can get the name and id of the transport
         NSString *tansportName = [transport objectForKey:@"transport_name"];
         NSString *transportId = [transport objectForKey:@"transport_id"];
    
         NSString *transportDescription = [NSString stringWithFormat:@"%@ - %@",transportId, transportName];
    
         cell.textLabel.text = transportDescription;
    
         return cell;
     }
    

    That’s the gist of it anyway.

    You might want to store the allKeys and allValues arrays as class properties instead of having to go through them in all the tableview’s delegate and datasource methods, but you should have all the info to build yuor table now.

    Hope this helps 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to figure this out for 2 days and could not
I have been trying to figure this out for a few days now and
I have been trying to figure this out for days. Hope someone can help.
For the past few days, I have been trying to figure out how to
I have been searching for days trying to figure out how to add dialog
I've been trying to figure out this XSLT/XML problem for the past few days
I have been working for a couple days trying to figure out how to
I have been hitting my head against the wall trying to figure this out
I've been trying to figure this out for 2 days now, and before anyone
I obviously new and have been trying to two days to figure out how

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.