[英]how to check if array is null or empty in ios sdk?
I want to check if my Bond is empty or null and NULL value. 我想检查我的Bond是否为空或null和NULL值。
{
Bonds =(
{
DOB = "12/09/1988";
about = "";
}
);
User = {
city = CA;
email = "karmhadadmtl@gmail.com";
};
success = True;
}
Second time this type get data how to check Bond key 第二次这种类型获取数据如何检查Bond键
{
Bonds = Null;
User = {
city = CA;
email = "developer.i12@gmail.com";
};
success = True;
}
You just check for nil
你只需检查nil
if(data[@"Bonds"]==nil){
NSLog(@"it is nil");
}
or 要么
if ([data[@"Bonds"] isKindOfClass:[NSNull class]]) {
NSLog(@"it is null");
}
if ([data[@"Bonds"] isKindOfClass:[NSNull class]] || data[@"Bonds"] == nil || [data[@"Bonds"] isEqualToString:@""]) {
}
[NSNull null] always returns a same object so this should work fine. [NSNull null]始终返回相同的对象,因此这应该可以正常工作。
if (dictionary[@"Bonds"] != [NSNull null]) {
// requried data is present, now check if it is nil or empty.
}
check: if (![dataArray isKindOfClass:[NSNull class]])
&& 检查: if (![dataArray isKindOfClass:[NSNull class]])
&&
check if it having elements [dataArray firstObject]
- to check array having one or more elements. 检查它是否有元素[dataArray firstObject]
- 检查具有一个或多个元素的数组。
The best possible way should be: 最好的方法应该是:
if (!data[@"Bonds"] || ![data[@"Bonds"] count]){
NSLog(@"Data Found");
}else{
NSLog(@"Data Not Found");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.