我试图向本地Wordpress服务器发送一个JSON,我的映射如下所示:
[RKMIMETypeSerialization registerClass:[RKNSJSONSerialization class] forMIMEType:@"text/html"];
RKObjectMapping *orderEntryMapping = [RKObjectMapping requestMapping];
[orderEntryMapping addAttributeMappingsFromDictionary:@{
@"title": @"title"
}];
RKRequestDescriptor *requestDescriptorOrderEntry = [RKRequestDescriptor requestDescriptorWithMapping:orderEntryMapping objectClass:[OrderSend class] rootKeyPath:@"posts" method:RKRequestMethodPOST];
[objectManager addRequestDescriptor:requestDescriptorOrderEntry];OrderSend类如下所示:
#import <Foundation/Foundation.h>
@interface OrderSend : NSObject
@property (nonatomic) NSString *title;
@end这是发送请求的方法:
-(void) submitOrder:(OrderSend *) order completionHandler:(ResultObjectHandler) completionBlock
{
RKObjectManager *objectManager = [RKObjectManager sharedManager];
NSDictionary *parameters = @{
@"json" : @"posts.create_post"
};
[objectManager postObject:order path:@"" parameters:parameters success:^(RKObjectRequestOperation *operation, RKMappingResult *result)
{
NSLog(@"We object mapped the response with the following result: %@", result);
completionBlock(result);
}
failure:^(RKObjectRequestOperation *operation, NSError *error)
{
[self handleFailure:operation withError:error];
}];
}
-(void) cancel{
[[RKObjectManager sharedManager].operationQueue cancelAllOperations];
}
-(void) handleFailure:(RKObjectRequestOperation *)operation withError:(NSError*)error {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
NSLog(@"Hit error: %@", error);
}我正在为Wordpress使用JSON,但我得到了以下错误:
{NSLocalizedDescription=No mappable object representations were found at the key paths searched., NSLocalizedFailureReason=The mapping operation was unable to find any nested object representations at the key paths searched: categories, posts
The representation inputted to the mapper was found to contain nested object representations at the following key paths: error, status
This likely indicates that you have misconfigured the key paths for your mappings., keyPath=null, DetailedErrors=(
)}有人能帮我吗?,谢谢
解决方案是创建一个响应描述符,如下所示:
RKResponseDescriptor *responseDescriptorOrderEntry = [RKResponseDescriptor responseDescriptorWithMapping:orderEntryMapping method:RKRequestMethodAny pathPattern:nil keyPath:@"" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[objectManager addResponseDescriptor:responseDescriptorOrderEntry];发布于 2014-03-31 22:55:34
您正在定义请求描述符,但没有定义响应描述符。因此,RestKit不知道如何处理响应。
您需要创建带有关联映射的响应描述符,以便RestKit知道如何应用响应。默认情况下,RestKit将尝试将响应数据应用于源对象(order),但它需要知道如何做到这一点.
https://stackoverflow.com/questions/22770477
复制相似问题