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?

1
  • 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. Commented Apr 20, 2013 at 11:54

1 Answer 1

3

"nodes" is an array. Try this one:

NSArray *nodes = resultsDictionary[@"nodes"];
NSDictionary *node = nodes[0];
node = node[@"node"]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.