我正在解析一个json数据,如果它有一个内容,那么该字段之一是一个数组.但是如果它没有内容,那么它只是一个字符串“No result”.
我使用以下代码来解析它: @H_403_3@-(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:YES]; //URL is called. if ([status isEqualToString:@"success"]) { if ([[[json objectForKey:@"Items"] objectForKey:@"item_list"] isKindOfClass:[NSString class]]) { _Label.text = [NSString stringWithFormat:@"0"]; ItemsArray = [[NSMutableArray alloc]init]; } else { ItemsArray = [[json objectForKey:@"Items"] objectForKey:@"item_list"]; NSLog(@"%d",[ItemsArray count]); float Amount = 0; NSLog(@"%d",[ItemsArray count]); if ([ItemsArray count]>0) { for (int i=0; i<[ItemsArray count]; i++) { NSMutableDictionary * temp3 = [ItemsArray objectAtIndex: i]; NSString * x = [temp3 objectForKey:@"final"]; Amount = Amount + [x floatValue]; } Label.text = [NSString stringWithFormat:@"%.2f",BidAmount]; } else { Label.text = [NSString stringWithFormat:@"0"]; } } [TableViewOutlet reloadData];
我使用以下代码来解析它: @H_403_3@-(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:YES]; //URL is called. if ([status isEqualToString:@"success"]) { if ([[[json objectForKey:@"Items"] objectForKey:@"item_list"] isKindOfClass:[NSString class]]) { _Label.text = [NSString stringWithFormat:@"0"]; ItemsArray = [[NSMutableArray alloc]init]; } else { ItemsArray = [[json objectForKey:@"Items"] objectForKey:@"item_list"]; NSLog(@"%d",[ItemsArray count]); float Amount = 0; NSLog(@"%d",[ItemsArray count]); if ([ItemsArray count]>0) { for (int i=0; i<[ItemsArray count]; i++) { NSMutableDictionary * temp3 = [ItemsArray objectAtIndex: i]; NSString * x = [temp3 objectForKey:@"final"]; Amount = Amount + [x floatValue]; } Label.text = [NSString stringWithFormat:@"%.2f",BidAmount]; } else { Label.text = [NSString stringWithFormat:@"0"]; } } [TableViewOutlet reloadData];
}
这很好用.
当字段返回字符串时我面临没问题.但是当字段是数组时,我被卡住了.
在第一次运行项目后,即使数组计数大于0,它也能正常工作.但是从第二次开始,也不会调用Cellforrowatindexpath方法….
这些是我的代码:
有人请帮帮我