开发者

How to parse a Dictionary according to its index?

I have a dictionary and i want to parse the dictionary according to the index of the keys inside dictionary.Actually i want to switch开发者_JAVA技巧 to different dictionaries as per the value of current variable which mean i want to keep accessing the object inside my dictionary according to the index.

k = k+1;
NSDictionary * checkBox = [step objectForKey:@"CheckBoxSingle"];
NSDictionary * first = [checkBox objectAtIndex:k];

Thanks


Here you have a couple of examples to iterate through an nsdictionary. Using his first example, you can access arbitery values using the array from [checkBox allKeys];. Not that you should do it using an NSDictionary because the order of stuff AFAIK can be completley random. You can look into sorting an NSArray though if it will serve your purpose.

Also NSDictionary implements NSFastEnumeration, which means that if you want you can do;

for (NSString *currentKey in checkBox)
{
    NSDictionary *current = [checkBox objectForKey:currentKey];
}


Use a for loop

int k;
for (k=0;k<LIMIT;k++) {  //change LIMIT to number of times to loop.
    NSDictionary * checkBox = [step objectForKey:@"CheckBoxSingle"];
    //NSDictionary doesn't respond to objectAtIndex:
    //do something...
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜