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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:42:35+00:00 2026-05-27T22:42:35+00:00

I have a json collection I am able to parse perfectly fine 1 level

  • 0

I have a json collection I am able to parse perfectly fine 1 level deep, but each item in the main collection has a collection in it. I am not quite sure how to access ‘item’ to get the sub collection like I did with the main collection…

NSString *response = [request responseString];
NSDictionary *json = [response JSONValue];

NSArray *items = [json valueForKeyPath:@"item"];

for (id item in items) 
{
    mainObject.name = [item objectForKey:@"name"];  //this works fine
    // How do I get sub collection from item?
}

Some of the json:

{"item":
    { 
      "available_at"     : null,
      "created_at"       : "2011-12-09T19:52:23Z",
      "lo_id"            : 30,
      "id"               : 24,
      "merchant_id"      : 1,
      "order_id"         : 25,
      "reach_local_link" : null,
      "status"           : null,
      "token"            : "12-258847891-1",
      "updated_at"       : "2011-12-09T19:52:23Z",
      "url"              : "api/dir/v1/item/12-258847891-1/print",
      "subitem1"         :
          {
             "area"      : "local",
             "broker_id" : "",
             "broker_id" : null,
             "category"  :
                 {
                     "category":....

In the example, there could be multiple sub items like subitem1. I need to get the collection of those and have another for loop inside the current one.

  • 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-27T22:42:35+00:00Added an answer on May 27, 2026 at 10:42 pm

    item will simply be a dictionary or array if it is one in the JSON object. For example, you should be able to do this:

    NSDictionary *subitem1 = [item objectForKey:@"subitem1"];
    

    It’s simply a NSDictionary in there, so you can use it as one.

    I really recommend logging the Objective-C representation of your JSON object, it makes it easier to work with it:

    NSLog(@"%@", json);
    

    Warning
    It’s strongly recommended to check the type of the objects you load before assuming that they really are dictionaries, strings or arrays. If they aren’t, you’ll notice that your application is going to crash.

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

Sidebar

Related Questions

I'm trying to deseralize some json into a collection (list), but I'm not sure
I have tried a lot but I have not been able to find out
I have done JSON parsing earlier but this one is not working for me.
I know this question has been asked many times, but I have not been
I have a json object collection of geo locations that I build in the
I have json data being returned as a collection: var foo = [6, 7,
I have a list that I need to fill using a JSON collection of
I have a JSON list that I want to iterate over, but skip the
I am new to android. I have a url which only has the json
I have a JSON array with ActiveRecord objects. These objects can be reconstructed using

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.