0

所以这是我的方法:

-(NSString *) getTemplateNamed: (NSString *) aTemplateName withManufacturerID: (NSNumber *) aManufacturerID withPriceLevel: (NSNumber *) aPriceLevel {
    @try {

        NSFetchRequest *request = [[NSFetchRequest alloc] init];
        [request setEntity:[NSEntityDescription entityForName:@"Manufacturer" inManagedObjectContext:self.managedObjectContext]];
        [request setPredicate:[NSPredicate predicateWithFormat:@"ManufacturerID==%@", aManufacturerID]];
        [request setFetchLimit:1];
        NSError *err=nil;
        NSArray *entities = [self.managedObjectContext executeFetchRequest:request error:&err];
        request=nil;

        NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:[[[entities lastObject] ManufacturerSettingsString] dataUsingEncoding:NSUTF8StringEncoding] options:kNilOptions error:nil];
        NSString *akey = [NSString stringWithFormat: @"PriceLevel%@", aPriceLevel ];
        if ([aPriceLevel isEqualToNumber:[NSNumber numberWithInt:0]]) {   akey=@"BasePrice"; }

        NSString *template = [dictionary valueForKey:aTemplateName];
        NSString *output = [template stringByReplacingOccurrencesOfString:@"Price" withString:[NSString stringWithFormat:@"%@Formatted", akey]];

        return  output;
    }
    @catch (NSException *exception) {
        return @"";
    }
}

根据 Profiler,这是有问题的行:

 NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:[[[entities lastObject] ManufacturerSettingsString] dataUsingEncoding:NSUTF8StringEncoding] options:kNilOptions error:nil];

看起来是导致问题的 NSJSONSerialization - 有什么想法吗?

4

0 回答 0