how to iterate nested dictionaries in objective-c iphone sdk

前端 未结 5 793
天命终不由人
天命终不由人 2021-01-13 11:35

Hi I have a json string converted unsing the JSON framework into a dictionary and I need to extract its content. How could I iterate to the nested dictionaries? I have alrea

5条回答
  •  萌比男神i
    2021-01-13 11:42

    I'm sure you have solved this at this point, but I found it convenient to write a recursive utility class function that recursively logs every key of a dictionary:

    /**
     *  Recursively logs the keys and values of each object in the dictionary,
     *  along with the class of the value.
     *
     *  @param dict The dictionary to inspect
     */
    + (void)logDictionaryKeys:(NSDictionary*)dict {
        for (id key in dict) {
            if ([dict[key] isKindOfClass:[NSDictionary class]]) {
                [self logDictionaryKeys:dict[key]];
            }else {
                NSLog(@"Key: %@", key);
                NSLog(@"Value: %@ (%@)", dict[key], [dict[key] class]);
            }
        }
    
        return;
    }
    

提交回复
热议问题