2012-11-22 97 views
4

Restkit 0.20RestKit 0.20 - 預計內容類型(空)

有誰知道我爲什麼每次調用都會得到這個輸出?任何關於追蹤它的建議?我可以在調試輸出中看到json有效載荷。

error=Error Domain=AFNetworkingErrorDomain Code=-1016 "Expected content type (null), got application/json" UserInfo=0x9187fe0 {NSLocalizedRecoverySuggestion={ 

我作出上述呼籲是

[manager getObjectsAtPath:@"/customers" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) { 
     NSArray* statuses = [mappingResult array]; 
     NSLog(@"Loaded customers: %@", statuses); 
    } failure:^(RKObjectRequestOperation *operation, NSError *error) { 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" 
                 message:[error localizedDescription] 
                 delegate:nil 
               cancelButtonTitle:@"OK" 
               otherButtonTitles:nil]; 
     [alert show]; 
     NSLog(@"Customer Error: %@", error); 
    }]; 

和我的映射代碼是

@interface DataCustomers : NSObject 

@property (nonatomic, copy) NSString* customerid; 
@property (nonatomic, copy) NSString* firstname; 
@property (nonatomic, copy) NSString* lastname; 
@property (nonatomic, copy) NSString* email; 

@end 



RKObjectMapping *map = [RKObjectMapping mappingForClass:[DataCustomers class]]; 
    [map addAttributeMappingsFromDictionary:@{ 
    @"id" : @"customerid", 
    @"firstname" : @"firstname", 
    @"lastname" : @"lastname", 
    @"email" : @"email"}]; 

[manager addResponseDescriptor: [RKResponseDescriptor responseDescriptorWithMapping:map 
                      pathPattern:@"/customers" 
                       keyPath:@"customers" 
                      statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]]; 
+0

似乎是某處的圖書館衝突。完全相同的代碼在新項目中沒有此錯誤。很奇怪。 – darren

回答

1

有一些奇怪的庫發生衝突完全糊塗AFNetwork。

除了消除這個問題,我在pathPattern中加了nil。

2

你正確設置你的意願來處理內容類型?

嘗試增加這AppDelegate中:

#import "RKMIMETypeSerialization.h" 
#import "RKNSJSONSerialization.h" 

[RKMIMETypeSerialization registerClass:[RKNSJSONSerialization class] forMIMEType:@"application/json"]; 
+0

與此無關。我遇到了一些與AFNetwork嚴重混淆的圖書館衝突。另外,我用nil替換了pathPattern。 – darren

+0

有趣。您可以爲您自己的這個問題添加一個答案,並通過這種方式接受它作爲解決方案。 – powerj1984

+1

好點...謝謝 – darren