我正在尝试通过 RestKit 0.20.3 映射对象,但我知道这些日志已经好几天了:
2013-08-12 18:32:08.158 MyAppIphone[848:5703] E restkit.network:RKResponseMapperOperation.m:304 Failed to parse response data: Loaded an unprocessable response (200) with content type 'application/json'
2013-08-12 18:32:08.174 MyAppIphone[848:5703] E restkit.network:RKObjectRequestOperation.m:238 POST 'myUrl' (200 OK / 0 objects)
[request=0.1305s mapping=0.0000s total=5.6390s]:
error=Error Domain=org.restkit.RestKit.ErrorDomain Code=-1017 "Loaded an unprocessable response (200) with content type 'application/json'"
UserInfo=0x1ed5a500 {NSErrorFailingURLKey=myUrl, NSUnderlyingError=0x1ed5b240 "The operation couldn’t be completed. (Cocoa error 3840.)", NSLocalizedDescription=Loaded an unprocessable response (200) with content type 'application/json'}
response.body={"my json content"}
这是 MyData 类:
#import <Foundation/Foundation.h>
@interface MyData : NSObject
@property (nonatomic, retain) NSString *criterias;
@end
这是我设置映射器的方法:
- (RKResponseDescriptor*) getDataMapping
{
// Mapping
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[MyData class]];
[mapping addAttributeMappingsFromDictionary:@{
@"criteriasHeader": @"criteriasHeader"
}];
// Status code
NSIndexSet *statusCodes = RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful);
// Descriptior
return [RKResponseDescriptor responseDescriptorWithMapping:mapping method:RKRequestMethodPOST pathPattern:nil keyPath:@"regions" statusCodes:statusCodes];
}
这是我的请求功能:
- (void) runRequestWithType:(RequestType)type baseUrl:(NSString *)baseUrlString path:(NSString *)path parameters:(NSDictionary *)parameters mapping:(RKResponseDescriptor *) descriptor
{
// Print heeader and body from the request and the response
RKLogConfigureByName("RestKit/Network", RKLogLevelTrace);
RKLogConfigureByName("Restkit/Network", RKLogLevelDebug);
RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelTrace);
RKLogConfigureByName("Restkit/ObjectMapping", RKLogLevelDebug);
// Set up the base url
NSURL *baseUrl = [NSURL URLWithString:baseUrlString];
//Run request in block
RKObjectManager *manager = [RKObjectManager managerWithBaseURL:baseUrl];
[manager addResponseDescriptorsFromArray:@[descriptor]];
[manager.router.routeSet addRoute:[RKRoute routeWithClass:[MyData class] pathPattern:path method:RKRequestMethodPOST]];
//[manager getObjectsAtPath:path parameters:parameters success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
[manager postObject:nil path:path parameters:parameters success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
if ([self.delegate respondsToSelector:@selector(requestDidSucceedWithType:andResponse:)]) {
[self.delegate requestDidSucceedWithType:type andResponse:[mappingResult firstObject]];
}
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
if ([self.delegate respondsToSelector:@selector(requestDidFailWithError:andError:)]) {
[self.delegate requestDidFailWithType:type andError:error];
}
}];
}
PS:我尝试使用较短的 JSON,效果很好。
我做错什么了吗?
你能帮帮我吗,谢谢。