2011-08-18 122 views
0

即时解析一个JSON文件。逻辑是这样的,如果没有数据名为boy.it的变量需要进入if循环,并且如果有数据进入else部分。但问题是,即使变量男孩是空的(这表明在控制台空)环路仍然进入别人part..cud u人帮我out..below是代码..if语句的问题

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
// Navigation logic may go here. Create and push another view controller. 
NSDictionary *boy=[url objectAtIndex:indexPath.row]; 
NSLog(@"the boy value:%@",boy); 
if (boy == NULL) 
{ 
Secondetailview *detailViewController1 = [[Secondetailview alloc] initWithItem:boy];  
[self.navigationController pushViewController:detailViewController1 animated:YES]; 
[detailViewController1 release];  
}else 
{ 
    FirstViewDetail *detailViewController = [[FirstViewDetail alloc] initWithItem:boy]; 

    [self.navigationController pushViewController:detailViewController animated:YES]; 
    [detailViewController release]; 
} 

} enter image description here

回答

2

我会尝试使用if (boy == nil)但这似乎并不奏效。

而是做到这一点:

NSString *str = [NSString stringWithFormat:@"%@", boy]; 
if ([str isEqualToString:@""]) { 
    //boy is nil do your stuff 
} 
+0

mkay ......我试着用nil..still无法进入,如果环...做ü没有的词典中的任何符号 – kingston

+0

那是绝对一样的 – hamstergene

+0

-1不正确。 'nil' =='NULL' =='0'(大致在最后一个),因为Objective-C只是挂在C/C++上。然而,在Objective-C中使用'nil'确实是更正确的:-) – 2011-08-18 05:24:45

-1

如下修改您若条件,看看是否能工程。

((boy == NULL) || ([boy count] == 0)) 
1

更换

if (boy == NULL) 

if ([boy count] == 0) 
+0

dude它不可能..to计数nsdictionary ...它的崩溃 – kingston

+0

你有NSDictionary * boy = [url objectAtIndex:indexPath.row]的问题; 。它不会返回字典.. –

+0

k..if dats如果我试过比较if(url == nil)并获得相同的结果coz它只有在url数据库im assingin在字典中的值 – kingston