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 @"";
    }
}

プロファイラーによると、問題のある行は次のとおりです。

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

問題を引き起こしているのは NSJSONSerialization のようです - 何かアイデアはありますか?

4

0 に答える 0