서버 반환값에서 0 길이의 빈 문자열 제거

3120 단어


// 
   if ([responseObject isKindOfClass:[NSDictionary class]]) {

    responseObject =   [[NetWorkManager sharedManager] removeEmptyStrAtDictionary:responseObject];

    }




// 
- (id)removeEmptyStrAtDictionary:(id)dict {
    
    
    // 
    if ([dict isKindOfClass:[NSDictionary class]]) {
        
        NSMutableDictionary* tmp  = [(NSDictionary*)dict mutableCopy];
        
        
        __weak typeof(self) weakSelf = self;
        
        [tmp enumerateKeysAndObjectsUsingBlock:^(id  _Nonnull key, id  _Nonnull obj, BOOL * _Nonnull stop) {
            
            __strong __typeof(self) strongSelf = weakSelf;
            
            
            if ([obj isKindOfClass:[NSString class]] && ((NSString*)obj).length <= 0 ) {
                
                
                [tmp removeObjectForKey:key];
                
                
                
            }else if ([obj isKindOfClass:[NSDictionary class]]){
                
                
                [tmp setObject:[strongSelf removeEmptyStrAtDictionary:obj] forKey:key];
                
                
            }else if ([obj isKindOfClass:[NSArray class]]){
                
                
                
                [tmp setObject:[strongSelf removeEmptyStrAtArray:obj] forKey:key];
                
                
                
            }
            
            
            
            
            
        }];
        
        
        
        dict = [tmp mutableCopy];
        
    }
    
    
    
    return dict;
    
    
}



- (NSArray*)removeEmptyStrAtArray:(id)orginArray {
    
    
    if ([orginArray isKindOfClass:[NSArray class]]){
        
        NSMutableArray*array = [orginArray mutableCopy];
        
        NSMutableArray*endArray = [NSMutableArray array];
        
        __weak typeof(self) weakSelf = self;
        
        [array enumerateObjectsUsingBlock:^(id  _Nonnull tmp, NSUInteger idx, BOOL * _Nonnull stop) {
            
            __strong __typeof(self) strongSelf = weakSelf;
          
            if ([tmp isKindOfClass:[NSDictionary class]]) {
                
                
                [endArray  addObject: [strongSelf removeEmptyStrAtDictionary:tmp]];
                
                
            }else if ([tmp isKindOfClass:[NSArray class]]){
                
                [endArray addObject:[strongSelf removeEmptyStrAtArray:tmp]];
                
                
            }else if ([tmp isKindOfClass:[NSString class]] && ((NSString*)tmp).length <= 0 ) {
                
                
               
                
                
            }else {
                
                
                [endArray addObject:tmp];
                
                
                
            }
            
            
            
            
            
            
        }];
        
      
    
    
    
       
        
        return endArray;
    
    
     
    }else {
        
        
        
        return orginArray;
        
    }
    
 
    
}








좋은 웹페이지 즐겨찾기