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

  • Home
  • SEARCH
  • 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 7598745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:29:04+00:00 2026-05-30T22:29:04+00:00

I’ve got this data I get from an XML feed and parse as NSDictionaries.

  • 0

I’ve got this data I get from an XML feed and parse as NSDictionaries. The data structure is like this:

item = {
  address =     {
    text = "1 Union Street";
  };
  data =     {
    text = "Hello.";
  };
  event_date =     {
    text = "2012-02-27";
  };
  event_type =     {
    text = pubQuiz;
  };
  latitude =     {
    text = "57.144994";
  };
  longitude =     {
    text = "-2.10143170000003";
  };
  name =     {
    text = "Mobile Tester";
  };
  picture =     {
    text = "public://pictures/event_default.png";
  };
  time =     {
    text = "23.00";
  };
  vname =     {
    text = Test;
  };
}
//More items

Each sub-section, ie, address, data, event_date etc are all NSDictonaries.

I would like to iterate through the whole collection and grab the “text” inside each of the sections to create an array of “items” with these properties. I’ve tried using the for..in loop structure in Objective-C but haven’t had any success so far. Has anyone got a few pointers? I’m happy to read through any good tutorials or examples on how to traverse nested NSDictionaries.

EDIT:

Alright so, after parsing the XML I get that structure up there. What I would like to do is traverse the “item” structure to extract the “text” fields of all the inner dictionaries – something like this:

foreach(item in array of dictionaries) {
  myItem.address = item.address.text;
  myItem.data = item.data.text;
  ...
}

And so on. I hope this makes it a little clearer.

So, the part where I’m stuck is where I want to set the properties of the item while traversing the NSDictionaries. This is what I have so far:

for(NSDictionary *item in self.eventsArray) {
    for (NSDictionary *key in [item allKeys]) {
        NSLog(@"%@", key);
        id value = [item objectForKey:key];
        if ([value isKindOfClass:[NSDictionary class]]) {
            NSDictionary* newDict = (NSDictionary*)value;
            for (NSString *subKey in [newDict allKeys]) {
                NSLog(@"%@", [newDict objectForKey:subKey]);
            }
        }
    }
}

Which outputs:

address
1 Union Street
data
Hello.
…

I’m just not sure how to select the proper attribute in the object I’m creating to set the required property, if that makes any sense?

  • 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-30T22:29:05+00:00Added an answer on May 30, 2026 at 10:29 pm

    To get the items I did the following:

    id eventsArray = [[[[XMLReader dictionaryForXMLData:responseData error:&parseError] objectForKey:@"root"] objectForKey:@"events"] objectForKey:@"event"];
    if([eventsArray isKindOfClass:[NSDictionary class]]) 
    {
        //there's only one item in the XML, so there's only an NSDictionary created.
        for(NSString *item in (NSDictionary*)eventsArray) 
        {
            //check what each item is and deal with it accordingly
        }
    } 
    else 
    {
        //There's more than one item in the XML, an array is created
        for(NSDictionary *item in (NSArray*)eventsArray) 
        {
            for (NSString *key in [item allKeys]) 
            {
              //check what value key is and deal with it accordingly
            }
        }
    }
    

    And that allows me to access all elements.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
I've got a string that has curly quotes in it. I'd like to replace
this is what i have right now Drawing an RSS feed into the php,
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I have a bunch of posts stored in text files formatted in yaml/textile (from
I'm working with an upstream system that sometimes sends me text destined for HTML/XML

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.