2014-07-16 10 views
0

다음 JSON을 매핑하는 방법을 찾지 못했습니다. 응답에서 hostedLargeUrl을 매핑하려고합니다. 나는이 문제에 대해 무엇을해야할지 모르겠다. 나의 정보가 충분히 상세하지 않다면 사과하고 싶다. 당신이 필요로하는 세부 사항의 유형이 너무 확실하지 않습니다. 미리 감사드립니다. 여기 RestKit지도를 만들 수 없습니다.

images: [ 
{ 
imageUrlsBySize: { 
90: "http://lh4.ggpht.com/ZXiwjS55Zk7oBu6GWaVr0HAqIPKumXwBfGtzsCWEFdrJSOXiCcC-I3TpUwrXBnP_DPNuBm-ib-4-3aXbs4mfXA=s90-c", 
360: "http://lh4.ggpht.com/ZXiwjS55Zk7oBu6GWaVr0HAqIPKumXwBfGtzsCWEFdrJSOXiCcC-I3TpUwrXBnP_DPNuBm-ib-4-3aXbs4mfXA=s360-c" 
}, 
hostedLargeUrl: "http://i.yummly.com/Pasta-with-garlicky-broccoli-rabe-305651-270310.l.jpg", 
hostedSmallUrl: "http://i.yummly.com/Pasta-with-garlicky-broccoli-rabe-305651-270310.s.jpg" 
} 

내 코드입니다 :

+ (RKMapping *)recipeDetailMapping 
{ 
    RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[RecipeDetails class]]; 

    [mapping addAttributeMappingsFromDictionary:@{ 

                @"attribution.text" : @"attributionText", 
                @"images.hostedLargeUrl" : @"images" 
                }]; 



    [mapping addAttributeMappingsFromArray:@[@"ingredientLines", 
              @"name", 
              @"totalTime", 

              ]]; 




    return mapping; 

} 

RecipeDetails 코드

- (void)loadRecipeDetails 
{ 
    NSIndexSet *statusCodeSet = RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful); 

    RKMapping *mapping = [MappingProvder recipeDetailMapping]; 



    NSString *resourcePath = [NSString stringWithFormat:@"/v1/api/recipe/%@", self.recipeInfo.recipeId]; 

    RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:mapping 
                          method:RKRequestMethodGET 
                         pathPattern:resourcePath 
                          keyPath:nil 
                         statusCodes:statusCodeSet]; 










    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.yummly.com/v1/api/recipe/%@?_app_id=%@&_app_key=%@&requirePictures=true", self.recipeInfo.recipeId 
             ,Yummly_APP_ID , Yummly_API_kEY ]]; 

    NSURLRequest *request = [NSURLRequest requestWithURL:url]; 



    RKObjectRequestOperation *operation = [[RKObjectRequestOperation alloc] initWithRequest:request 
                     responseDescriptors:@[responseDescriptor]]; 

    [operation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) { 




     self.recipeData = mappingResult.array; 


     [self updateUI]; 


     [SVProgressHUD dismiss]; 
     [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; 





    } failure:^(RKObjectRequestOperation *operation, NSError *error) { 

     NSLog(@"Error: %@", error); 
     NSLog(@"Response: %@", operation.HTTPRequestOperation.responseString); 

     [SVProgressHUD showErrorWithStatus:@"Request Failed"]; 
    }]; 



    [operation start]; 





} 

답변

0

소스 데이터를 배열에의

@property (nonatomic, copy) NSArray *ingredientLines; 
@property (nonatomic, copy) NSString *name; 
@property (nonatomic, copy) NSString *totalTime; 
@property (nonatomic, copy) NSString *attributionText; 
@property (nonatomic, copy) NSString *images; 

마지막 비트 당신은 처리해야 그걸로 어떤 식 으로든.

옵션 1. 변경 NSArray *images;

옵션 2 의 속성은 사용자 정의 방식 setImageArray:를 추가하고 첫 번째 이미지를 추출하고 저장을 구현합니다. 그런 다음 대상 키를 imageArray으로 사용하도록 매핑을 변경합니다.

다른 옵션은 실제로 다른 개체 그래프가 필요합니다 ...

+0

감사합니다. – TylerMiller47