这是我的回复
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);
这里第一个响应图像即将到来的数据,第二个响应图像没有数据。然后如何写if条件。
答案 0 :(得分:1)
NSNumber * isSuccessNumber = (NSNumber *)[abc4 valueForKey:@"image"];
if([isSuccessNumber boolValue] == YES)
{
NSLog(@"Image is available");
} else {
NSLog(@"Image is not available");
}
你的回答是这样的
第一个条件:
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 强>
图片不可用
答案 1 :(得分: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
}
}
}
欢呼
答案 2 :(得分:0)
您存储的Dictionary
内Array
。
//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
}
答案 3 :(得分:0)
您需要检查图像(数据)是否为零
首先你可以直接检查
if(abc5 length] == 0)
{
....
}
else
{
....
}
然后将图像(数据)转换为字符串(abc5)
09/29 13:54:36: Launching app
$ adb push /Users/user/AndroidStudioProjects/MyApplication/app/build/outputs/apk/app-debug.apk /data/local/tmp/com.example.user.myapplication
$ adb shell pm install -r "/data/local/tmp/com.example.user.myapplication"
Aborted
$ adb shell am start -n "com.example.user.myapplication/com.example.user.myapplication.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Error while executing: am start -n "com.example.user.myapplication/com.example.user.myapplication.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.user.myapplication/.MainActivity }
Error type 3
Error: Activity class {com.example.user.myapplication/com.example.user.myapplication.MainActivity} does not exist.
Error while Launching activity