Restkit 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 :(得分:2)
您是否正确设置了处理内容类型的意愿?
尝试将此添加到您的AppDelegate:
#import "RKMIMETypeSerialization.h"
#import "RKNSJSONSerialization.h"
[RKMIMETypeSerialization registerClass:[RKNSJSONSerialization class] forMIMEType:@"application/json"];
答案 1 :(得分:1)
发生了一些奇怪的图书馆冲突,使AFNetwork完全混淆。
除了删除该问题外,我还将nil添加到pathPattern。