Search code examples
iphonexcodejsonnsdictionarysbjson

SBJson won't go as deep in NSDictionary


I've been banging my head on the wall all day because of this.

I'm trying to parse this JSON blob here.

This is what I'm using:

NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];

NSDictionary *results = [responseString JSONValue];

NSArray *allTweets = [[results objectForKey:@"response"] objectForKey:@"posts"];

However, when I try to do this:

NSURL *url = [NSURL URLWithString:[[[[aTweet objectForKey:@"posts"] objectForKey:@"photos"] objectForKey:@"original_size"] objectForKey:@"url"]];

It gives me no error but the *url is set as "null".

I've used CFShow for the NSDictionary but everything after the "photos" key comes out as a regular string and not JSON formatted.

Can anyone tell me why?

Thanks in advance for all your help.


Solution

  • try this.

        for (int i = 0; i < [[[results objectForKey:@"response"] objectForKey:@"posts"] count]; i++) {
            NSLog(@"url data = %@",[[[[[[[results objectForKey:@"response"]
            objectForKey:@"posts"] objectAtIndex:i] objectForKey:@"photos"]
            objectAtIndex:0] objectForKey:@"original_size"] objectForKey:@"url"]);
        }