Objective c if语句有问题

Objective c if语句有问题,objective-c,xcode,Objective C,Xcode,我正在解析一个json文件。如果名为boy的变量中没有数据,逻辑是这样的。它必须进入if循环,如果有数据,它必须进入else部分。但问题是即使变量boy为空(在控制台中显示为空)循环仍然进入else部分..因为你们帮助我..下面是代码 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // Navigation logic may go here. Creat

我正在解析一个json文件。如果名为boy的变量中没有数据,逻辑是这样的。它必须进入if循环,如果有数据,它必须进入else部分。但问题是即使变量boy为空(在控制台中显示为空)循环仍然进入else部分..因为你们帮助我..下面是代码

- (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];
}
}
如果(boy==nil),我会尝试使用
,但这似乎也不起作用

而是这样做:

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

修改您的if条件,如下所示,看看是否有效

((boy == NULL) || ([boy count] == 0))
替换

if (boy == NULL) 


mkay…我尝试使用nil..仍然无法进入if循环…没有任何字典符号..-1不正确
nil
=
NULL
=
0
(大致在最后一个上),因为Objective-C只是挂在C/C++上。然而,在Objective-C:-)@kingston中使用
nil
更符合习惯用法。好的,我想我现在有了正确的解决方案,请查看更新的帖子@麦克斯纳:老兄,你搞定了。谢谢..上面的代码工作得很好很酷,也请投票!不要忘记在if语句之后释放字符串,以避免内存泄漏!伙计,这是不可能的..要计算nsdictionary…它会崩溃您对nsdictionary*boy有问题=[url objectAtIndex:indexPath.row]。它不返回Dictionary..k..if dats de case我尝试比较if(url==nil)并得到相同的结果,因为它在dictionary@kingston:@RaviChokshi,Sidnicious:伙计们。。感谢你的努力,我能够使代码工作…上面的答案使它工作
if ([boy count] == 0)