我正在使用以下代碼來檢查NSNumber是否具有零值。所以我將NSNumber轉換爲字符串,並檢查它的長度是否爲0.如果它爲零,則返回NSNull,否則我會返回數字本身。NSNull返回<null>而不是返回null
- (id)NSNullToNilForKey:(NSNumber *)number
{
if ([[number stringValue] length] == 0){
return [NSNull null];
}
return number;
}
林調用它,如下所示,
NSString *bodyString = [NSString stringWithFormat:@"[ \"%@\",{\"session_token\": \"%@\",\"request\": [\"GetAssigneeWiseCompliancesChart\",{\"country_id\": %@,\"business_group_id\": %@,\"legal_entity_id\": %@,\"division_id\": %@,\"unit_id\": %@,\"user_id\": %@}]}]",clientSessionId,clientSessionId,[self NSNullToNilForKey:countryId],[self NSNullToNilForKey:businessGroupId],[self NSNullToNilForKey:legalEntityId],[self NSNullToNilForKey:divId],[self NSNullToNilForKey:unitId], [self NSNullToNilForKey:userId]];
但問題是,雖然如果循環得到調用。從NSNullToNilForKey的if循環返回的值是<null>
而不是null
。我怎樣才能解決這個問題?
是什麼意思'如果循環得到調用valu' –
我已經更新了我的問題 – Roger
可我知道你爲什麼想要將null傳遞給服務器 –