我有一個數組,我從數據庫中獲取某些特定值的數據,因此該特定值不存在的關鍵在於它正在獲取數組中的空值。如何消除nsarray中的空值?
現在,我的問題是如何消除數組中的空值?我嘗試將nsarray值提取到nsstring,然後將其提取到另一個數組,但不是獲取整個數組,而是獲取最後一個索引值。
請幫我一把。謝謝。
我附上代碼以備將來參考:
NSString *url = [NSString stringWithFormat:@"webservice from where i m fetching data"];
NSLog(url);
NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
[request setHTTPMethod: @"POST"];
NSData *returnData = [ NSURLConnection sendSynchronousRequest:request returningResponse: nil error: nil ];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding: NSUTF8StringEncoding];
dataArray=[[returnString JSONValue] retain];
[self setAlldetails:dataArray];
nsarray *InteName = [alldetails valueForKey:@"IntelligenceName"];
所以抓取數組的數組InteName值是這樣的:
(
"00:00:00",
"00:00:00",
"17:15:00",
"17:15:00",
"17:15:00",
"17:15:00",
"00:00:00",
"00:00:00",
"17:15:00",
"17:15:00",
"17:15:00",
"17:15:00",
"<null>",
"<null>",
"<null>",
"<null>",
"<null>",
"<null>",
"<null>",
"<null>",
"<null>"
)
所以現在,我想刪除null值的次數。
任何猜測?
給一些代碼來跟蹤你的代碼中的錯誤。 – Ishu 2010-11-26 07:11:48
filteredArrayUsingPredicate :.比下面的解決方案更少的代碼。 – 2017-03-16 00:01:34
此外,如果它的運行時間比O(n)更好,我不會感到驚訝。 – 2017-03-16 00:03:17