4

休息套件 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)]];
4

2 回答 2

2

您是否正确设置了处理内容类型的意愿?

尝试将此添加到您的 AppDelegate:

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

[RKMIMETypeSerialization registerClass:[RKNSJSONSerialization class] forMIMEType:@"application/json"];
于 2012-12-08T14:45:04.033 回答
1

发生了一些奇怪的库冲突,完全混淆了 AFNetwork。

除了消除这个问题之外,我还在 pathPattern 中添加了 nil。

于 2012-12-19T05:57:17.483 回答