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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:06:20+00:00 2026-05-27T20:06:20+00:00

Using NSJSONSerialization on a returned NSData from a network call I get back a

  • 0

Using NSJSONSerialization on a returned NSData from a network call I get back a nested structure of NSDictionaries and NSArrays.

Now I wanted to parse that tree structure and prepare it for further use. Each node of the tree always carries an NSArray of sub nodes (NSDictionaries). Every one of these nodes should have a back reference to it’s parent node, containing the NSArray the sub node is part of.

This is a basic example of the structure I am talking about:

Node {
 nodes:[
  node {parent:Node,name:foo},
  node {parent:Node,name:bar},
  node {parent:Node,name:baz},
 ]
,name:root}

Each node is an NSDictionary and each sub nodes collection an NSArray, containing NSDictionaries.

I learned, that I cannot just add a new key “parent” and set its value to the parent node dictionary. That creates a segfault when calling the object.

Basic example of the code, creating the parent key:

NSMutableDictionary * foo = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"foo",@"name",[NSNumber numberWithInt:1],@"value",nil];
NSMutableDictionary * bar = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"bar",@"name",[NSNumber numberWithInt:2],@"value",nil];
NSMutableDictionary * baz = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"baz",@"name",[NSNumber numberWithInt:3],@"value",nil];

NSMutableArray *array = [NSMutableArray arrayWithObjects:foo,bar,baz,nil];

NSMutableDictionary * container = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"root",@"name",array,@"nodes",nil];

[foo setValue:container forKey:@"parent"];

NSLog(@"%@",foo);  // <-- segfault here

Why am I getting a segmentation fault? Is this an infinite loop while printing out the description of the structure because of the back reference in the parent key of the node?

Dou you guys have any other approach to this problem here? Do I have to hold an external representaion of the tree structure, pointing to each key or IS there actually a way of storing some kind of reference to the parent node??

Many, many thanks in advance!!!

  • 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-27T20:06:20+00:00Added an answer on May 27, 2026 at 8:06 pm

    It seems to me that you can use a simple objective C class here with the interface like

    @interface Node : NSObject {
        Node              *parent;
        NSMutableArray    *nodes;
        NSString          *name
    }
    @end
    

    I am not sure if this is the best way to do it, but you should not be using NSDictionary. The reason why you are getting the segmentation fault is probably because of the back reference creating an infinite loop in the NSLog.

    EDIT: Upon googling, I found that there is a class NSTreeNode which should make things simpler for you.

    http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/NSTreeNode_class/Introduction/Introduction.html

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

Sidebar

Related Questions

I'm using a new API class, NSJSONSerialization, especially the following method : + (id)JSONObjectWithData:(NSData
Using jQuery, how do I get the value from a textbox and then load
I am trying to use NSJSONSerialization to serialize the data returned from stack overflow
Using the following database table structure: Order Table: OrderId OrderName OrderItem Table: OrderId ItemId
using file_get_contents , I open an Internet URL and get the contents of this
Using the current request I can get the URL hostname with: HttpContext.Current.Request.Url.Host But -
Using the http://www.ifans.com/forums/showthread.php?t=132024 post from another question i am allowing the user to enter
Using the C# Facebook SDK 5.0.3 everything works fine whit the client.Get(/me). But when
using VB.Net2010 I need to call a C# DLL The problem I have is
Using Java, how can I extract all the links from a given web page?

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.