The Apple client receives data in the background and converts it into objects before it can be used. While some beginners or lazy people may directly use the results put back in the background without object conversion, or even whatever type of data are treated as strings, and then converted to numbers and other types defined by the interface. If the NSNumber type is returned in the background, this lazy writing will directly cause flash back. The best solution is: The client will return the background data through the MJExtension third-party library for object conversion, Not directly use background data (self. ShopHomeEntity. ShopHomeResultHeadEntity = [CBPShopHomeResultHeadEntity Mj_objectWithKeyValues: resultDic]) . Cardtype = self. DataDic [@”shopCardTypeResponse”][@”cardType”]; // Boolean type 0 or 1. If ([self.cardType intValue] == 1). The best solution, of course, is to refactor the code and use it all as objects. What happens when you don’t have time to refactor your code? There are two temporary schemes: 1. Perform secondary conversion on all returned strings in the background. All key/value pairs whose values are of NSNumber type are converted to standard strings. 2. The iOS client scans the received result at the bottom level of the network request component to see if the value of the key-value pair is of NSNumber type, and converts it into a standard string if it is:

if([result isKindOfClass:[NSNumber class]])
    {
        return [NSString stringWithFormat:@"% @", result];
    }
Copy the code

The data returned in the background generally has only these types: / / dictionaries – > array – > / / / dictionaries – > – > array – > dictionary / / dictionaries – > – > dictionary / / arrays – > dictionary – > – > dictionary / / / / arrays – > – > dictionary arrays – > dictionary – > – > dictionary My following function is able to double convert all of the key/value pairs in the background data of this interface that are of type NSNumber to a standard string.

The data returned in the background is either a standard string of all-digit type or an NSNumber type, such as the cardType field.

The data returned in the background is either a standard string of all-digit type or an NSNumber type, such as the cardType field. Of course, that’s the case with string acceptance.

Of course, if([self.cardType intValue] == 1), then the type is out of bounds.

The following is a function that converts all the values of the background result key-value pair to a standard string. Id result= [self modifyNSNumber:data];

-(id)modifyNSNumber:(id)result
{
    if(nil == result)
    {
        return result;
    }
    else if([result isKindOfClass:[NSNull class]])
    {
        return nil;
    }
    else if([result isKindOfClass:[NSNumber class]])
    {
        return [NSString stringWithFormat:@"% @", result];
    }
    else if([result isKindOfClass:[NSString class]])
    {
        return result;
    }
    else if([result isKindOfClass:[NSDictionary class]])
    {
        NSMutableDictionary *resultDic = [NSMutableDictionary dictionary];
        NSDictionary *dic1 = (NSDictionary *)result;
        for(NSInteger i = 0; i <dic1.allKeys.count; i++) { NSString *key1 = dic1.allKeys[i]; NSString *value1 = dic1.allValues[i];// if([value1 isKindOfClass:[NSNull class]])
            if(nil == value1)
            {
                // There is no defensive programming
            }
            else if([value1 isKindOfClass:[NSNull class]])
            {
                [resultDic setValue:value1 forKey:key1];
            }
            else if([value1 isKindOfClass:[NSString class]])
            {
                [resultDic setValue:value1 forKey:key1];
            }
            else if([value1 isKindOfClass:[NSNumber class]])
            {
                
                [resultDic setValue:[NSString stringWithFormat:@"% @", value1] forKey:key1];
            }
            else if([value1 isKindOfClass:[NSArray class]])
            {
                NSArray *arr3 = (NSArray *)value1;/ / 2 layer
                NSMutableArray *arr4 = [NSMutableArray array];
                for(NSInteger i3 = 0; i3 <arr3.count; i3++) { id value5 = arr3[i3];/ / layer 3
                    if(nil == value5)
                    {
                        // There is no defensive programming
                    }
                    else if([value5 isKindOfClass:[NSNull class]])
                    {
                        [arr4 addObject:value5];
                    }
                    else if([value5 isKindOfClass:[NSNumber class]])
                    {
                        [arr4 addObject:[NSString stringWithFormat:@"% @", value5]];
                    }
                    else if([value5 isKindOfClass:[NSString class]])
                    {
                        [arr4 addObject:value5];
                    }
                    else if([value5 isKindOfClass:[NSDictionary class]])
                    {
                        NSMutableDictionary *resultDic6 = [NSMutableDictionary dictionary];/ / layer 4
                        NSDictionary *dic5 = (NSDictionary *)value5;
                        for(NSInteger i6 = 0; i6 <dic5.allKeys.count; i6++) { NSString *key7 = dic5.allKeys[i6];/ / on the seventh floor
                            NSString *value7 = dic5.allValues[i6];
                            if(nil == value5)
                            {
                                // There is no defensive programming
                            }
                            else if([value5 isKindOfClass:[NSNull class]])
                            {
                                [resultDic6 setValue:value7 forKey:key7];
                            }
                            else if([value7 isKindOfClass:[NSNumber class]])
                            {
                                [resultDic6 setValue:[NSString stringWithFormat:@"% @", value7] forKey:key7];
                            }
                            else if([value5 isKindOfClass:[NSString class]])
                            {
                                [resultDic6 setValue:value7 forKey:key7];
                            }
                            else
                            {
                                [resultDic6 setValue:value7 forKey:key7];
                            }
                        }
                        [arr4 addObject:resultDic6];
                    }
                }
                [resultDic setValue:arr4 forKey:key1];/ / on the second floor
            }// array - > dictionary
            else if([value1 isKindOfClass:[NSDictionary class]])
            {
                NSMutableDictionary *resultDic2 = [NSMutableDictionary dictionary];/ / on the second floor
                NSDictionary *dic2 = (NSDictionary *)value1;
                for(NSInteger i2 = 0; i2 <dic2.allKeys.count; i2++) { NSString *key2 = dic2.allKeys[i2];/ / three layers
                    NSString *value2 = dic2.allValues[i2];
                    if(nil == value2)
                    {
                        // There is no defensive programming
                    }
                    else if([value2 isKindOfClass:[NSNull class]])
                    {
                        [resultDic2 setValue:value2 forKey:key2];
                    }
                    else if([value2 isKindOfClass:[NSNumber class]])
                    {
                        [resultDic2 setValue:[NSString stringWithFormat:@"% @", value1] forKey:key1];
                    }
                    else if([value2 isKindOfClass:[NSString class]])
                    {
                        [resultDic2 setValue:value2 forKey:key2];
                    }
                    else if([value2 isKindOfClass:[NSArray class]])
                    {
                        NSArray *arr3 = (NSArray *)value2;/ / four layers
                        NSMutableArray *arr4 = [NSMutableArray array];
                        for(NSInteger i3 = 0; i3 <arr3.count; i3++) { id value5 = arr3[i3];/ / fifth floor
                            if(nil == value5)
                            {
                                // There is no defensive programming
                            }
                            else if([value5 isKindOfClass:[NSNull class]])
                            {
                                [arr4 addObject:value5];
                            }
                            else if([value5 isKindOfClass:[NSNumber class]])
                            {
                                [arr4 addObject:[NSString stringWithFormat:@"% @", value5]];
                            }
                            else if([value5 isKindOfClass:[NSString class]])
                            {
                                [arr4 addObject:value5];
                            }
                            else if([value5 isKindOfClass:[NSDictionary class]])
                            {
                                NSMutableDictionary *resultDic6 = [NSMutableDictionary dictionary];/ / the sixth floor
                                NSDictionary *dic5 = (NSDictionary *)value5;
                                for(NSInteger i6 = 0; i6 <dic5.allKeys.count; i6++) { NSString *key7 = dic5.allKeys[i6];/ / on the seventh floor
                                    NSString *value7 = dic5.allValues[i6];
                                    if(nil == value5)
                                    {
                                        // There is no defensive programming
                                    }
                                    else if([value5 isKindOfClass:[NSNull class]])
                                    {
                                        [resultDic6 setValue:value7 forKey:key7];
                                    }
                                    else if([value7 isKindOfClass:[NSNumber class]])
                                    {
                                        [resultDic6 setValue:[NSString stringWithFormat:@"% @", value7] forKey:key7];
                                    }
                                    else if([value5 isKindOfClass:[NSString class]])
                                    {
                                        [resultDic6 setValue:value7 forKey:key7];
                                    }
                                    else
                                    {
                                        [resultDic6 setValue:value7 forKey:key7];
                                    }
                                }
                                [arr4 addObject:resultDic6];
                            }
                        }
                        [resultDic2 setValue:arr4 forKey:key2];
                    }// dictionary - > array - dictionary
                    else if([value2 isKindOfClass:[NSDictionary class]])
                    {
                        NSMutableDictionary *resultDic6 = [NSMutableDictionary dictionary];/ / layer 4
                        NSDictionary *dic5 = (NSDictionary *)value2;
                        for(NSInteger i6 = 0; i6 <dic5.allKeys.count; i6++) { NSString *key7 = dic5.allKeys[i6];/ / 5 layers
                            NSString *value7 = dic5.allValues[i6];
                            if(nil == value7)
                            {
                                // There is no defensive programming
                            }
                            else if([value7 isKindOfClass:[NSNull class]])
                            {
                                [resultDic6 setValue:value7 forKey:key7];
                            }
                            else if([value7 isKindOfClass:[NSNumber class]])
                            {
                                [resultDic6 setValue:[NSString stringWithFormat:@"% @", value7] forKey:key7];
                            }
                            else if([value7 isKindOfClass:[NSString class]])
                            {
                                [resultDic6 setValue:value7 forKey:key7];
                            }
                            else
                            {
                                [resultDic6 setValue:value7 forKey:key7];
                            }
                        }
                        [resultDic2 setValue:resultDic6 forKey:key2];
                    }// Dictionary - > dictionary
                    else
                    {
                        [resultDic2 setValue:value1 forKey:key1];/ / on the second floor
                    }
                }
                [resultDic setValue:resultDic2 forKey:key1];/ / z on the second floor
            }
            else{ [resultDic setValue:value1 forKey:key1]; }}return  resultDic;
    }
    else if([result isKindOfClass:[NSArray class]])
    {
        NSArray *arr1 = (NSArray *)result;
        NSMutableArray *arr2 = [NSMutableArray array];/ / a layer
        for(NSInteger i1 = 0; i1 <arr1.count; i1++) { id value1 = arr1[i1];if(nil == value1)
            {
                // There is no defensive programming
            }
            else if([value1 isKindOfClass:[NSNull class]])
            {
                [arr2 addObject:value1];
            }
            else if([value1 isKindOfClass:[NSNumber class]])
            {
                [arr2 addObject:[NSString stringWithFormat:@"% @", value1]];
            }
            else if([value1 isKindOfClass:[NSString class]])
            {
                [arr2 addObject:value1];
            }
            else if([value1 isKindOfClass:[NSDictionary class]])
            {
                NSMutableDictionary *resultDic2 = [NSMutableDictionary dictionary];/ / on the second floor
                NSDictionary *dic2 = (NSDictionary *)value1;
                for(NSInteger i2 = 0; i2 <dic2.allKeys.count; i2++) { NSString *key2 = dic2.allKeys[i2];/ / three layers
                    NSString *value2 = dic2.allValues[i2];
                    if(nil == value2)
                    {
                        // There is no defensive programming
                    }
                    else if([value2 isKindOfClass:[NSNull class]])
                    {
                        [resultDic2 setValue:value2 forKey:key2];
                    }
                    else if([value2 isKindOfClass:[NSNumber class]])
                    {
                        [resultDic2 setValue:[NSString stringWithFormat:@"% @", value2] forKey:key2];
                    }
                    else if([value2 isKindOfClass:[NSString class]])
                    {
                        [resultDic2 setValue:value2 forKey:key2];
                    }
                    else if([value2 isKindOfClass:[NSArray class]])
                    {
                        NSArray *arr3 = (NSArray *)value2;/ / four layers
                        NSMutableArray *arr4 = [NSMutableArray array];
                        for(NSInteger i3 = 0; i3 <arr3.count; i3++) { id value5 = arr3[i3];/ / fifth floor
                            if(nil == value5)
                            {
                                // There is no defensive programming
                            }
                            else if([value5 isKindOfClass:[NSNull class]])
                            {
                                [arr4 addObject:value5];
                            }
                            else if([value5 isKindOfClass:[NSNumber class]])
                            {
                                [arr4 addObject:[NSString stringWithFormat:@"% @", value5]];
                            }
                            else if([value5 isKindOfClass:[NSString class]])
                            {
                                [arr4 addObject:value5];
                            }
                            else if([value5 isKindOfClass:[NSDictionary class]])
                            {
                                NSMutableDictionary *resultDic6 = [NSMutableDictionary dictionary];/ / the sixth floor
                                NSDictionary *dic6 = (NSDictionary *)value5;
                                for(NSInteger i6 = 0; i6 <dic6.allKeys.count; i6++) { NSString *key7 = dic6.allKeys[i6];/ / on the seventh floor
                                    NSString *value7 = dic6.allValues[i6];
                                    if(nil == value7)
                                    {
                                        // There is no defensive programming
                                    }
                                    else if([value7 isKindOfClass:[NSNull class]])
                                    {
                                        [resultDic6 setValue:value7 forKey:key7];
                                    }
                                    else if([value7 isKindOfClass:[NSNumber class]])
                                    {
                                        [resultDic6 setValue:[NSString stringWithFormat:@"% @", value7] forKey:key7];
                                    }
                                    else if([value7 isKindOfClass:[NSString class]])
                                    {
                                        [resultDic6 setValue:value7 forKey:key7];
                                    }
                                    else
                                    {
                                        [resultDic6 setValue:value7 forKey:key7];
                                    }
                                }
                                [arr4 addObject:resultDic6];
                            }
                        }
                        [resultDic2 setValue:arr4 forKey:key2];
                    }// Array - dictionary - > array - dictionary
                    else
                    {
                        [resultDic2 setValue:value2 forKey:key2];/ / on the second floor
                    }
                }
                [arr2 addObject:resultDic2];/ / on the second floor
            }
            else if([value1 isKindOfClass:[NSArray class]])
            {
                NSArray *arr3 = (NSArray *)value1;/ / 2 layer
                NSMutableArray *arr4 = [NSMutableArray array];
                for(NSInteger i3 = 0; i3 <arr3.count; i3++) { id value5 = arr3[i3];/ / layer 3
                    if(nil == value5)
                    {
                        // There is no defensive programming
                    }
                    else if([value5 isKindOfClass:[NSNull class]])
                    {
                        [arr4 addObject:value5];
                    }
                    else if([value5 isKindOfClass:[NSNumber class]])
                    {
                        [arr4 addObject:[NSString stringWithFormat:@"% @", value5]];
                    }
                    else if([value5 isKindOfClass:[NSString class]])
                    {
                        [arr4 addObject:value5];
                    }
                    else if([value5 isKindOfClass:[NSDictionary class]])
                    {
                        NSMutableDictionary *resultDic6 = [NSMutableDictionary dictionary];/ / layer 4
                        NSDictionary *dic5 = (NSDictionary *)value5;
                        for(NSInteger i6 = 0; i6 <dic5.allKeys.count; i6++) { NSString *key7 = dic5.allKeys[i6];/ / 5 layers
                            NSString *value7 = dic5.allValues[i6];
                            if(nil == value7)
                            {
                                // There is no defensive programming
                            }
                            else if([value7 isKindOfClass:[NSNull class]])
                            {
                                [resultDic6 setValue:value7 forKey:key7];
                            }
                            else if([value7 isKindOfClass:[NSNumber class]])
                            {
                                [resultDic6 setValue:[NSString stringWithFormat:@"% @", value7] forKey:key7];
                            }
                            else if([value7 isKindOfClass:[NSString class]])
                            {
                                [resultDic6 setValue:value7 forKey:key7];
                            }
                            else
                            {
                                [resultDic6 setValue:value7 forKey:key7];
                            }
                        }
                        [arr4 addObject:resultDic6];
                    }
                }
                [arr2 addObject:arr4];/ / on the second floor
            }// array - > dictionary
            else
            {
                [arr2 addObject:value1];/ / on the second floor}}return arr2;// Return array - dictionary - > array - dictionary
    }
    else
    {
        returnresult; }}Copy the code