2016-09-29 40 views
1

这是我的回应如何编写BOOL的条件值

1.{ 

    image = nbYijSxVXDOFGWFk8BhZUpU 
    "is_food_in_time_product" = 1; 
    "list_price" = "2.8"; 
    name = Export; 

} 
2. 
{ 

    image = 0; 
    "is_food_in_time_product" = 1; 
    "list_price" = 1; 
    name = "K\U00e4se"; 

} 

NSString *abc5 = [abc4 valueForKey:@"image"]; 
NSLog(@"%@",abc5); 

这里第一响应图像未来数据,第二反应图像没有data.Then怎么写,如果条件。

+0

你必须拯救abc4中的数据? –

+0

abc 4是NSDictionary ???? –

+0

abc4是一个数组? –

回答

1

后,你必须这样做:

NSDictionary *responseDataDictionary = responseObject; 
    //here responce object is your total data which is coming from server 
    NSArray *array = [[responseDataDictionary valueForKey:@"result"] valueForKey:@"products"]; 
      for (NSDictionary *dict in array) 
      { 
       NSString *str = [dict valueForKey:@"image"]; 
       if([str isKindOfClass:[NSString class]]) 
       { 
        NSLog(@"YES"); 
        //here you have to add your image as usual to another mutable array 
       }else{ 
        NSLog(@"NO"); 
        // bool value happens means this will execute 
        // Here you have to add custom image ie.placeholder image 
       } 

      } 
    } 

就是这样的欢呼声

+1

Tq u for posting –

0

这是您存储的Array中的Dictionary

//Here index is an integer value, showing the index of an array responseArray. 
if[responseArray[index][@"image"] intValue]!=0){ 

    //Load image 
}else{ 
    //Do not load image 
} 
1
NSNumber * isSuccessNumber = (NSNumber *)[abc4 valueForKey:@"image"]; 
if([isSuccessNumber boolValue] == YES) 
{ 
    NSLog(@"Image is available"); 
} else { 
    NSLog(@"Image is not available"); 
} 

你的反应是这样的

1条件:

NSDictionary *r1 = @{@"bool" : @(1)}; 

NSNumber * isSuccessNumber = (NSNumber *)[r1 valueForKey:@"bool"]; 
if([isSuccessNumber boolValue] == YES) 
{ 
    NSLog(@"Image is available"); 
} else { 
    NSLog(@"Image is not available"); 
} 

输出1

图片可

第二个条件:

NSDictionary *r1 = @{@"bool" : @(0)}; 

NSNumber * isSuccessNumber = (NSNumber *)[r1 valueForKey:@"bool"]; 
if([isSuccessNumber boolValue] == YES) 
{ 
    NSLog(@"Image is available"); 
} else { 
    NSLog(@"Image is not available"); 
} 

输出2

图片不能

+0

图像= 0是从服务器 –

+0

来BOOL值我正在上面的代码的应用程序运行崩溃显示这个错误[__ NSCFBoolean isEqualToString:]:无法识别的选择发送到实例0x10746c528' –

+0

@SivaSankar请请参阅编辑答案 –

0

您需要检查是否图像(数据)为零或不

首先,你可以直接检查

if (image != nil) 
{ 
    .... 
} 
else{ 
    ... 
} 

然后基于URL转换图像(数据)转换成字符串(ABC5)

if(abc5 length] == 0) 
{ 
    .... 
} 
else 
{ 
    .... 
}