使用 restkit 0.23.3 发送多部分:响应映射为空
Send multipart with restkit 0.23.3: response mapping is empty
我正在尝试 post 一个对象(行走)到我的服务器。
[[RKObjectManager sharedManager] postObject:walk path:urlPath
parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSLog(@"It Worked: %@", mappingResult );
if(mappingResult.count==0) {
[self alertStatus:@"Error" :@"Erreur" :0];
return;
}...
问题是 mappingResult 总是空的。
在日志中我有以下内容:
回复:
restkit.object_mapping:RKMapperOperation.m:320 Examining keyPath '<null>' for mappable content...
2015-01-11 22:49:56.250 XXXX restkit.object_mapping:RKMapperOperation.m:300 Found mappable data at keyPath '<null>': {
errors = "<null>";
message = success;
reason = "<null>";
result = "<null>";
status = SUCCESS;
}
2015-01-11 22:49:56.251 XXXX D restkit.object_mapping:RKMapperOperation.m:403 Finished performing object mapping. Results: {
}
2015-01-11 22:49:56.255 XXXX T restkit.network:RKObjectRequestOperation.m:218 POST 'http://XXXX' (200 OK / 0 objects) [request=2.0944s mapping=0.0100s total=2.1111s]:
response.headers={
"Cache-Control" = "no-cache, no-store";
Connection = "Keep-Alive";
"Content-Type" = "application/json";
Date = "Sun, 11 Jan 2015 21:48:28 GMT";
Expires = "Thu, 01 Jan 1970 00:00:00 GMT";
"Keep-Alive" = "timeout=15, max=99";
Pragma = "no-cache";
"Transfer-Encoding" = Identity;
}
response.body={"status":"SUCCESS","message":"success","reason":null,"result":null,"errors":null}
2015-01-11 22:49:56.258 XXXX It Worked: <RKMappingResult: 0x1685b750, results={
}>
我添加了这个 responseDescriptor:
RKResponseDescriptor * descriptor = [RKResponseDescriptor responseDescriptorWithMapping:[ResponseModel defineResponseRequestMapping]
method:RKRequestMethodPOST
pathPattern:nil
keyPath:nil
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[[RKObjectManager sharedManager] addResponseDescriptor:descriptor];
我尝试了不同的 pathPattern,但它不起作用。
映射:
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[ResponseModel class]];
[mapping addAttributeMappingsFromDictionary:@{
@"status": @"status",
@"reason": @"reason",
@"message": @"message",
@"errors": @"errors",
@"result": @"result"
}];
任何人都可以帮助我为什么我的 mappingResult 总是空的,即使我从 Restkit 没有错误?
非常感谢您的帮助!
感谢您的留言。
我刚刚在 link: RestKit POST response with wrong mapping 上找到了解决方案。
RestKit 对响应使用与请求相同的映射。你必须强迫它。
谢谢
我正在尝试 post 一个对象(行走)到我的服务器。
[[RKObjectManager sharedManager] postObject:walk path:urlPath
parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSLog(@"It Worked: %@", mappingResult );
if(mappingResult.count==0) {
[self alertStatus:@"Error" :@"Erreur" :0];
return;
}...
问题是 mappingResult 总是空的。
在日志中我有以下内容:
回复:
restkit.object_mapping:RKMapperOperation.m:320 Examining keyPath '<null>' for mappable content...
2015-01-11 22:49:56.250 XXXX restkit.object_mapping:RKMapperOperation.m:300 Found mappable data at keyPath '<null>': {
errors = "<null>";
message = success;
reason = "<null>";
result = "<null>";
status = SUCCESS;
}
2015-01-11 22:49:56.251 XXXX D restkit.object_mapping:RKMapperOperation.m:403 Finished performing object mapping. Results: {
}
2015-01-11 22:49:56.255 XXXX T restkit.network:RKObjectRequestOperation.m:218 POST 'http://XXXX' (200 OK / 0 objects) [request=2.0944s mapping=0.0100s total=2.1111s]:
response.headers={
"Cache-Control" = "no-cache, no-store";
Connection = "Keep-Alive";
"Content-Type" = "application/json";
Date = "Sun, 11 Jan 2015 21:48:28 GMT";
Expires = "Thu, 01 Jan 1970 00:00:00 GMT";
"Keep-Alive" = "timeout=15, max=99";
Pragma = "no-cache";
"Transfer-Encoding" = Identity;
}
response.body={"status":"SUCCESS","message":"success","reason":null,"result":null,"errors":null}
2015-01-11 22:49:56.258 XXXX It Worked: <RKMappingResult: 0x1685b750, results={
}>
我添加了这个 responseDescriptor:
RKResponseDescriptor * descriptor = [RKResponseDescriptor responseDescriptorWithMapping:[ResponseModel defineResponseRequestMapping]
method:RKRequestMethodPOST
pathPattern:nil
keyPath:nil
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[[RKObjectManager sharedManager] addResponseDescriptor:descriptor];
我尝试了不同的 pathPattern,但它不起作用。 映射:
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[ResponseModel class]];
[mapping addAttributeMappingsFromDictionary:@{
@"status": @"status",
@"reason": @"reason",
@"message": @"message",
@"errors": @"errors",
@"result": @"result"
}];
任何人都可以帮助我为什么我的 mappingResult 总是空的,即使我从 Restkit 没有错误?
非常感谢您的帮助!
感谢您的留言。 我刚刚在 link: RestKit POST response with wrong mapping 上找到了解决方案。
RestKit 对响应使用与请求相同的映射。你必须强迫它。
谢谢