从数组到json获取以下数据,StatusArray是
(
(
5
),
(
4
),
(
3
),
(
5
),
(
1
),
(
1
)
)
现在我需要将这些值与整数值进行比较,并将其添加到tableview单元格标签中。我的代码是,
NSDictionary* json = [NSJSONSerialization
JSONObjectWithData:data
options:kNilOptions
error:&error];
NSLog(@"%@", json);
totalArray =[json objectForKey:@"Files"];
NSLog(@"%@", totalArray);
fileIdArray=[[NSMutableArray alloc]init];
loanNumberArray=[[NSMutableArray alloc]init];
borrowerArray=[[NSMutableArray alloc]init];
adressArray=[[NSMutableArray alloc]init];
statusArray=[[NSMutableArray alloc]init];
ordersArray=[[NSMutableArray alloc]init];
for (int i=0; i<[[json objectForKey:@"Files"] count]; i++)
{
[fileIdArray addObject:[[totalArray objectAtIndex:i]objectForKey:@"FileID"]];
[loanNumberArray addObject:[[totalArray objectAtIndex:i]objectForKey:@"LoanDetails"]];
[borrowerArray addObject:[[totalArray objectAtIndex:i]objectForKey:@"Borrower"]];
[adressArray addObject:[[totalArray objectAtIndex:i]objectForKey:@"PropertyAddress"]];
[ordersArray addObject:[[totalArray objectAtIndex:i]objectForKey:@"Orders"]];
}
statusArray = [ordersArray valueForKey:@"Status"];
if ([statusArray containsObject:@"1"])
{
UILabel *statusLabel = (UILabel *)[cell viewWithTag:105];
statusLabel.text=@"New";
NSString *label=statusLabel.text;
NSLog(@"%@",label);
}
else if([statusArray containsObject:[NSNumber numberWithInteger:2]])
{
UILabel *statusLabel = (UILabel *)[cell viewWithTag:105];
statusLabel.text=@"Pending";
NSString *label=statusLabel.text;
NSLog(@"%@",label);
}
else if([statusArray containsObject:@"4"])
{
UILabel *statusLabel = (UILabel *)[cell viewWithTag:105];
statusLabel.text=@"Accepted";
NSString *label=statusLabel.text;
NSLog(@"%@",label);
}
else if([statusArray containsObject:@"5"])
{
UILabel *statusLabel = (UILabel *)[cell viewWithTag:105];
statusLabel.text=@"Completed";
NSString *label=statusLabel.text;
NSLog(@"%@",label);
}
我无法找到标签文本,也没有找到任何条件。我的代码有问题请纠正我。
由于
答案 0 :(得分:0)
试试这个:
for (int x=0; x<[StatusArray count]; x++) {
NSMutableArray *array = [StatusArray objectAtIndex:x];
NSString *string = [NSString stringWithFormat:@"%@",[array objectAtIndex:0]];
if ([string isEqualToString:@"1"])
{
UILabel *statusLabel = (UILabel *)[cell viewWithTag:105];
statusLabel.text=@"New";
NSString *label=statusLabel.text;
NSLog(@"%@",label);
}
else if([string isEqualToString:@"2"])
{
UILabel *statusLabel = (UILabel *)[cell viewWithTag:105];
statusLabel.text=@"Pending";
NSString *label=statusLabel.text;
NSLog(@"%@",label);
}
else if([string isEqualToString:@"4"])
{
UILabel *statusLabel = (UILabel *)[cell viewWithTag:105];
statusLabel.text=@"Accepted";
NSString *label=statusLabel.text;
NSLog(@"%@",label);
}
else if([string isEqualToString:@"5"])
{
UILabel *statusLabel = (UILabel *)[cell viewWithTag:105];
statusLabel.text=@"Completed";
NSString *label=statusLabel.text;
NSLog(@"%@",label);
}
}
答案 1 :(得分:0)
您的statusArray
是一个数组数组。而你正在尝试将数组与字符串进行比较。
试试这个:
UILabel *statusLabel = (UILabel *)[cell viewWithTag:105];
if ([statusArray containsObject:@[@1]])
{
statusLabel.text=@"New";
NSString *label=statusLabel.text;
NSLog(@"%@",label);
}
else if([statusArray containsObject:@[@2]])
{
statusLabel.text=@"Pending";
NSString *label=statusLabel.text;
NSLog(@"%@",label);
}
else if([statusArray containsObject:@[@3])
{
statusLabel.text=@"Accepted";
NSString *label=statusLabel.text;
NSLog(@"%@",label);
}
else if([statusArray containsObject:@[@4])
{
statusLabel.text=@"Completed";
NSString *label=statusLabel.text;
NSLog(@"%@",label);
}