0

I have this json returned from a cms and I need to break it apart and use the different values.

{"nodes":
     [{"node":
        {"created":"14012013165204","lastupdated":"03042013133901","type":"News"}
     }]
}

I use JSONKit framework and here is my code:

    NSString* theURL = [NSString stringWithFormat:@"http://testserver.com/content_lastupdate.json"];
    NSError* err = nil;
    NSURLResponse* response = nil;
    NSMutableURLRequest* request = [[NSMutableURLRequest alloc] init];
    NSURL*URL = [NSURL URLWithString:theURL];
    [request setURL:URL];
    [request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
    [request setTimeoutInterval:30];
    NSData* data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];

    NSString *output = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    NSDictionary *resultsDictionary = [output objectFromJSONString];

    NSLog([NSString stringWithFormat:(@"Response: %@"), output]);

    NSDictionary *nodes = [resultsDictionary objectForKey:@"nodes"];
    NSObject *node = [nodes objectForKey:@"node"];

I do not know how to get the next part of the results. nodes key is found but the next one is not. Any idea what basics I'm missing here?

NickOpris
  • 509
  • 2
  • 8
  • 20
  • A) Learn how to read JSON -- it's very simple. Check out JSON.org. B) Use NSLog. It prints out decoded JSON objects in a JSON-like syntax (though `()` is used instead of `[]`), so you can see the structure as you "peel" each layer. – Hot Licks Apr 20 '13 at 11:54

1 Answers1

3

"nodes" is an array. Try this one:

NSArray *nodes = resultsDictionary[@"nodes"];
NSDictionary *node = nodes[0];
node = node[@"node"]
Vladimir Obrizan
  • 2,538
  • 2
  • 18
  • 36