简体   繁体   中英

Print keys of NSDictionary instead of values

I download some content from a json webservice.

Is it possible print the keys and not the values instead? For the eventuality of not knowing what the keys are.

for( NSString *aKey in [dictionary allKeys] )
{
    // do something like a log:
    NSLog(aKey);
}

OR

NSLog([dictionary allKeys]);

This should do the trick

You should be able to use the NSDictionary's keyEnumerator method to get the keys, then you can loop through them and print them out.

Borrowing an example from Apple:

NSEnumerator *enumerator = [myDictionary keyEnumerator];
id key;

while ((key = [enumerator nextObject])) {
    NSLog(@"Do something with the key here:%@",key);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM