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 7876965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:15:12+00:00 2026-06-03T03:15:12+00:00

I’m trying to split json data I have in a NSDictonary into smaller parts

  • 0

I’m trying to split json data I have in a NSDictonary into smaller parts i can use, however I seem te be stuck.

The data i’m receiving from the api I use is current public transport data. This is the data I receive:

{
    Storingen =     {
        Gepland =         {
            Storing =             {
                Advies = "U kunt gebruikmaken van de omreisroute of de bussen reis tussen Alphen a/d Rijn en Gouda met de NS-bus reis vanaf zondag 29 april van Alphen a/d Rijn naar Gouda met de trein via Woerden reis tussen Leiden Centraal en Gouda via Den Haag Centraal";
                Bericht = "
\n        <p>
\n            <b>Wanneer: van zaterdag 28 april tot en met zondag 6 mei</b>
\n            <br/>
\n            <b>Oorzaak: door geplande werkzaamheden</b>
\n            <br/>
\n            <b>Advies: U kunt gebruikmaken van de omreisroute of de bussen</b>
\n            <br/>\treis tussen Alphen a/d Rijn en Gouda met de NS-bus<br/>\treis vanaf zondag 29 april van Alphen a/d Rijn naar Gouda met de trein via Woerden<br/>\treis tussen Leiden Centraal en Gouda via Den Haag Centraal<br/><br/><b>Extra Reistijd: een kwartier tot een half uur</b><br/></p>
\n    ";
                Oorzaak = "door geplande werkzaamheden";
                Periode = "van zaterdag 28 april tot en met zondag 6 mei";
                Traject = "Alphen a/d Rijn-Gouda";
                Vertraging = "een kwartier tot een half uur";
                id = "2012_apn_gd_28apr_6mei";
            };
        };
        Ongepland = "";
    };
}

Sofar I have this:

-(void)loadJson
{
    dispatch_async(kBgQueue, ^{
        NSData* data = [NSData dataWithContentsOfURL:kJsonURL];
        [self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES];
    });

}

- (void)fetchedData:(NSData *)responseData {
    NSError* error;
    NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
    NSDictionary *storingen = [json objectForKey:@"Storingen"];
    NSDictionary *gepland = [storingen objectForKey:@"Gepland"];

    NSLog(@"%@", json);

}

Currently the api is only returning one “Gepland”, planned, “Storing”, malfunction. But there can be more melfunctions at the save time. The api returns this as an array in the “Storing” key. My question is, how can I, lets say, loop trough the “Storing items and user their data to make a table view with just one label and a detail view with all the other information?

  • 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-06-03T03:15:13+00:00Added an answer on June 3, 2026 at 3:15 am

    Use can use the data from the dictionary as the data source in your table. What I think you will have in return is an NSArray with NSDictionaries. So it should look like this:

    NSArray *storingen = [json objectForKey:@"Storingen"];
    
    for (NSDictionary *storing in storingen ){
         NSString *advies = [storing objectForKey:@"Advies"];
    }
    

    However, the anoying part with JSON and common pasers is that if there only is 1 disruption (Een storing is one disruption), you will get an NSDictionary, otherwise if there are several you will get an NSArray. You can solve that this way:

    - (void)fetchedData:(NSData *)responseData {
        NSError* error;
        NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
        id storingen = [json objectForKey:@"Storingen"];
        NSDictionary *gepland = [storingen objectForKey:@"Gepland"];
    
        NSMutableArray *result = [[NSMutableArray alloc] init];
    
        if ([storingen isKindOfClass:[NSArray class]]) {
            result = storingen;
        }
        else {
            [result addObject:storingen];
        }
    }
    

    Now, storingen will always be an array and you can use that array to display it in a UITableView e.g.

    Veel success!

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to loop through a bunch of documents I have to put
I have some data like this: 1 2 3 4 5 9 2 6
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

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.