我正在遍历字典的结果,第一个键是“TC”,下一个键是“TC2”,依此类推。下面代码中的 while 语句循环到 TC1,然后循环到 TC12。它是添加一个字符而不是对 i 进行添加。如何通过循环为每个 TC 添加 1。
例如:TC1、TC2、TC3等。
NSString *key = @"TC";
dict = [resp objectForKey:key];
NSString* cNum = [dict objectForKey:@"CSHR_NUM"];
NSString* usrn = [dict objectForKey:@"CSHR_POS_NAME"];
NSLog( @"First for Cashier Num=%@, Cashier Name=%@", cNum, usrn);
if (cNum != IDNUM) {
// key = [NSString stringWithFormat:@"%@%d", key, i];
NSLog(@"KEY after if %@", key);
dict = [resp objectForKey:key];
cNum = [dict objectForKey:@"CSHR_NUM"];
usrn = [dict objectForKey:@"CSHR_POS_NAME"];
NSLog(@"c1= %@ , %@", cNum, usrn);
while (cNum != NULL) {
int i = 0;
NSLog(@"Key on While %@", key);
i++;
key = [NSString stringWithFormat:@"%@%d", key, i];
dict = [resp objectForKey:key];
cNum = [dict objectForKey:@"CSHR_NUM"];
usrn = [dict objectForKey:@"CSHR_POS_NAME"];
NSLog(@"c2= %@ , %@", cNum, usrn);
NSLog(@"KEY %@", key);
}
}