0

我无法使用 RestKit 将我的 JSON 映射到模型。XCode 上的记录器说

2013-09-12 16:35:00.543 EMoney[1291:342f] T restkit.object_mapping:RKMappingOperation.m:902 Performing mapping operation: <RKMappingOperation 0x20155890> for 'EMEcommerceInquiryResponse' object. Mapping values from object {
} to object *nil description* with object mapping (null)
2013-09-12 16:35:00.550 EMoney[1291:342f] T restkit.object_mapping:RKMappingOperation.m:571 Did not find mappable attribute value keyPath 'status'

这是json响应

response.body={"status":"NOT_ENOUGH_CREDITS","statusdesc":"no credits"}

这是我的映射代码

RKObjectMapping *ecommerceInquiryMapping = [RKObjectMapping mappingForClass:[EMEcommerceInquiryResponse class]];
    [ecommerceInquiryMapping addAttributeMappingsFromArray:@[@"status",@"statusdesc"]];
    RKResponseDescriptor *responseEcommerceInquiryDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:ecommerceInquiryMapping
                                                                                                   pathPattern:EM_API_SPECIAL_OFFER_INQUIRY
                                                                                                       keyPath:nil
                                                                                                   statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
    [objectManager addResponseDescriptor:responseEcommerceInquiryDescriptor];

这是我的对象类

#import <Foundation/Foundation.h>

@interface EMEcommerceInquiryResponse : NSObject
@property (retain, nonatomic) NSString *status;
@property (retain, nonatomic) NSString *statusdesc;
@end

这是我尝试打印状态时的日志

2013-09-12 17:06:55.042 EMoney[1343:907] STATUS (null)

有人知道我的代码有什么问题吗?我对其他映射使用类似的代码,它们工作正常。

4

0 回答 0