2

I've been wrestling with this all day and have no idea what i'm doing wrong. I have an NSDictionary

NSDictionary*dict=[tutorialsNodes objectAtIndex:0];

When I NSLog(@"%@",dict); it returns the following...

{
nodeAttributeArray =     (
            {
        attributeName = class;
        nodeContent = style1;
    }
);
nodeChildArray =     (
            {
        nodeContent = "Number of Patrons Using Facility: 151";
        nodeName = text;
    },
            {
        nodeName = br;
    },
            {
        nodeContent = "
\n      Room Occupancy: 210 ";
        nodeName = text;
    },
            {
        nodeName = br;
    },
            {
        nodeContent = "
\n      Current Wait: 0 minutes ";
        nodeName = text;
    }
);
nodeName = p;
}

However, when I enter the following code...

NSArray*dictArray=[dict objectForKey:@"nodeChildArray"];
NSLog(@"%@",dictArray);

It returns null . I am trying to pull the nodeContent from the NodeChildArray key but I can't even pull the key yet. Not sure why it keeps returning null

REVISION

Here are the exact lines that I am executing...

//some HTML parsing before this
NSArray *tutorialsNodes = [tutorialsParser   
searchWithXPathQuery:tutorialsXpathQueryString];

NSDictionary*dict=[tutorialsNodes objectAtIndex:0];

NSArray*dictArray=[dict objectForKey:@"nodeChildArray"];

NSLog(@"%@",dictArray);

It returns null twice

EXC_BAD_ACCESS
  • 346
  • 1
  • 4
  • 19
pj409
  • 337
  • 2
  • 9
  • 21
  • 2
    This output does not look like it was generated from a dictionary object. I suspect it was not serialized properly and is really just a string. Try asking the dictionary for all of its keys with `NSLog(@"%@", [dictArray allKeys]);` to verify that it is serialized properly. – fearmint Mar 01 '13 at 02:17
  • 1
    Verify that `dict` isn't `nil`. If it isn't, then `dict` doesn't have a key of `@"nodeChildArray"`. – rmaddy Mar 01 '13 at 02:17
  • Show us the lines that you're executing, in the precise order that you're executing them, with the NSLog statements included, and with a summary of the relevant declarations. Most likely you're losing "dict" between the first statement and the second. – Hot Licks Mar 01 '13 at 02:35
  • 1
    @JoePasq - If the output of the first statement were a string the `objectForKey` on it would fail with "selector not recognized". My bet is that the first and second statement are not back-to-back, and "dict" never makes it between them. (The output *does* look like a `description` of an NSDictionary.) – Hot Licks Mar 01 '13 at 02:38
  • I just added the code verbatim. – pj409 Mar 01 '13 at 02:47
  • dict does not return nil, it returns the dictionary I posted in the question. So that means @"nodeChildArray" isn't a key then? – pj409 Mar 01 '13 at 02:52
  • @pj409: try printing [dict allKeys] – Anoop Vaidya Mar 01 '13 at 02:54
  • 1
    The app crashed when I print [dict allKeys]...I get the following errror *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[TFHppleElement allKeys]: unrecognized selector sent to instance – pj409 Mar 01 '13 at 02:56
  • aha... so there is some problem.... try loging [dict className] – Anoop Vaidya Mar 01 '13 at 02:56
  • It won't let me...X code saya 'No Visible @interface for 'NSDictionary' declares the selector 'className' – pj409 Mar 01 '13 at 03:00
  • amazing sometimes it gets TFHppleElement and here agan NSDictinary. what about nslogging `[dict class];` – Anoop Vaidya Mar 01 '13 at 03:02
  • There we go...it's a TFHippleElement. Thanks for all your help by the way! much appreciated. – pj409 Mar 01 '13 at 03:05
  • Is there a way to somehow convert it into an NSDictionary? – pj409 Mar 01 '13 at 03:09
  • So, based on the code you posted, you *were not* logging "dict" when you said you were (several times). – Hot Licks Mar 01 '13 at 03:36
  • No, I was definitely logging dict, I just tried it again. When I logged [dict class] I got TFHippleElement. But that dictionary-looking code was the output for log dict. – pj409 Mar 01 '13 at 03:50
  • But the above code does not show that NSLog. You've never given us the straight story. – Hot Licks Mar 01 '13 at 18:05
  • Good call Hot Licks and Anoop. – fearmint Mar 02 '13 at 02:55

1 Answers1

1

As per your comment :

The app crashed when I print [dict allKeys]...I get the following errror *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[TFHppleElement allKeys]: unrecognized selector sent to instanc

That is why you are not able to extract value based on Key. You are getting THppleElement from the dictionary. You need to again parse this TFHppleElement to NSDictionary to get the required valueForKey.

Community
  • 1
  • 1
Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140