Search code examples
iosobjective-cjsonnsdictionaryflickr

How do I get all values from a NSDictionaries inside an NSDictionary?


Im working with flickr and in the sample fetch I get this:

{
    "api_key" =     {
        "_content" = 3c6eeeae4711a5f478d3da796750e06b;
    };
    format =     {
        "_content" = json;
    };
    method =     {
        "_content" = "flickr.test.echo";
    };
    nojsoncallback =     {
        "_content" = 1;
    };
    stat = ok;
}

This is a dictionary with 5 entries (api_key, format, method, nojsoncallback & stat). The first 4 entires are dictionaries themselves.

First off, there is a 5th element in my original dictionary, which is not a dictionary, it is simply the last entry in the original dictionary (the one stat=ok). Furthermore, I want the _content key in every subentry to appear in my individual cells but I dont want to hardcode any values. Do I HAVE to setup an array?


Solution

  • Try this

    for (NSString *key in dictionary){
        id object = dictionary[key];
        if ([object isKindOfClass:[NSDictionary class]]) {
        //Now you can work on the dictionary object
        }
    }