编辑2 由于我不太明白的原因,将响应描述符直接添加到httpsRKManager,而不是应用程序分层,让RK识别"响应"响应描述符。现在的问题是它似乎没有识别" ErrorStatus"的属性映射。 / end edit
我有三个问题。 First Shops和递归对象Shop不会显示为LLSResult对象的一部分。其次,对象不会从结果中填充,第三,有一种方法可以完全跳过商店。上下文是我将现有的应用程序从Ruby服务器迁移到具有不同api的.NET服务器。复合问题。两个星期前,我从未接触过Mac。更不用说任何生态系统。
编辑2: 响应描述符修复
NSString *path = [[ConfigManager sharedInstance] getEventsURL];
[[[AppCore sharedInstance] httpsRKManager]addResponseDescriptor:
[RKResponseDescriptor responseDescriptorWithMapping:[LLSResponse jsonMapping]
method:RKRequestMethodAny
pathPattern:path
keyPath:@"Response"
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]];
// This didn work
//[BaseRO addResponseDescriptorForPathPattern: [[ConfigManager sharedInstance] getEventsURL]
// withMapping:[LLSResponse jsonMapping]];
编辑日志2:
} to object with object mapping (null) 2015-12-11 10:19:24.805 The Clymb[5234:149794] D restkit.object_mapping:RKPropertyInspector.m:131 Cached property inspection for Class 'LLSResponse': { debugDescription = { isPrimitive = 0; keyValueCodingClass = NSString; name = debugDescription; }; description = { isPrimitive = 0; keyValueCodingClass = NSString; name = description; }; events = { isPrimitive = 0; keyValueCodingClass = Events; name = events; }; hash = { isPrimitive = 1; keyValueCodingClass = NSNumber; name = hash; }; shops = { isPrimitive = 0; keyValueCodingClass = Shops; name = shops; }; status = { isPrimitive = 0; keyValueCodingClass = ErrorStatus; name = status; }; } 2015-12-11 10:19:24.805 The Clymb[5234:149797] D restkit.object_mapping:RKMappingOperation.m:592 Mapping one to one relationship value at keyPath 'ErrorStatus' to 'ErrorStatus' 2015-12-11 10:19:24.806 The Clymb[5234:149797] T restkit.object_mapping:RKMappingOperation.m:550 Performing nested object mapping using mapping ErrorStatus> for data: { "@ID" = ""; "@Status" = OK; } 2015-12-11 10:19:24.806 The Clymb[5234:149797] D restkit.object_mapping:RKMappingOperation.m:868 Starting mapping operation... 2015-12-11 10:19:24.807 The Clymb[5234:149797] T restkit.object_mapping:RKMappingOperation.m:869 Performing mapping operation: for 'ErrorStatus' object. Mapping values from object { "@ID" = ""; "@Status" = OK; } to object with object mapping (null)
编辑结束2
JSON
{
Response: {
ErrorStatus: {
@ID: "",
@Status: "OK"
},
Events: {
Event: [
{
@Title: "Test - Hero 1",
@ID: "00010033005800000000",
@Start: "2015-12-07 09:00:00Z",
@End: "2015-12-31 08:00:00Z",
@Status: "Active",
@Image_Small: "http://www.leftlanesports.com/App_Themes/Default/graphics/Events/291_00010033005800000000.jpg",
@Image_Large: "http://www.leftlanesports.com/App_Themes/Default/graphics/Events/447_00010033005800000000.jpg",
@TypeCode: "EVTH1",
Description: {
#cdata-section: "yo"
},
ShortDescription: {
#cdata-section: "50%##Hero Event 1"
}
},
...
]
},
Shops: {
Shop: [
{
@Title: "Adventures",
@ID: "00030000000000000000"
},
{
@Title: "Apparel",
@ID: "00080000000000000000",
Shop: [
{
@Title: "Mens",
@ID: "00080001000000000000",
Shop: [
{
@Title: "Accessories",
@ID: "00080001003700000000",
Shop: [
.h文件
#import
#import "BaseRO.h"
#import "EventDO.h"
@class LLSResponse;
@class Events;
@class ErrorStatus;
@interface LLSResponse : NSObject
@property (nonatomic, strong) ErrorStatus * status;
@property (nonatomic, strong) Events * events;
- getAllEvents;
@end
@interface ErrorStatus : NSObject
@property (nonatomic, copy) NSString * _id;
@property (nonatomic, copy) NSString * Status;
@end
@interface Events : NSObject ;
@property (nonatomic, strong) NSMutableArray *events;
@end
@interface Shop : NSObject ;
@property (nonatomic, copy) NSString * _id;
@property (nonatomic, copy) NSString * title;
@property (nonatomic, strong) NSMutableArray *shops;
@end
@interface Shops : NSObject ;
@property (nonatomic, strong) NSMutableArray * shops;
@end
编辑2之后的相关部分似乎是Response.jsonMapping和ErrorStatus.jsonMapping。
.m文件
@implementation LLSResponse
+ (RKObjectMapping *)jsonMapping
{
RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelTrace); //??? debugging
RKObjectMapping * entityMapping = [RKObjectMapping mappingForClass:[LLSResponse class]];
[entityMapping addPropertyMapping:
[RKRelationshipMapping relationshipMappingFromKeyPath:@"ErrorStatus"
toKeyPath:@"ErrorStatus"
withMapping:[ErrorStatus jsonMapping]]];
[entityMapping addPropertyMapping:
[RKRelationshipMapping relationshipMappingFromKeyPath:@"Shops"
toKeyPath:@"Shops"
withMapping:[Shops jsonMapping]]];
[entityMapping addPropertyMapping:
[RKRelationshipMapping relationshipMappingFromKeyPath:@"Events"
toKeyPath:@"Events"
withMapping:[Events jsonMapping]]];
return entityMapping;
}
- (NSArray *) getAllEvents
{
Events * events = self.events;
NSArray *allEvents = events.events;
return allEvents;
}
@end
@implementation ErrorStatus
+ (RKObjectMapping *)jsonMapping
{
RKObjectMapping * entityMapping = [RKObjectMapping mappingForClass:[ErrorStatus class]];
[entityMapping addAttributeMappingsFromDictionary:@{
@"@ID" : @"_id",
@"@Status" : @"Status"
}];
return entityMapping;
}
@end
@implementation Events
+ (RKObjectMapping *)jsonMapping
{
RKObjectMapping * entityMapping = [RKObjectMapping mappingForClass:[Events class]];
[entityMapping addPropertyMapping:
[RKRelationshipMapping relationshipMappingFromKeyPath:@"Event"
toKeyPath:@"Event"
withMapping:[EventDO jsonMapping]]];
return entityMapping;
}
@end
@implementation Shop
+ (RKObjectMapping *)jsonMapping
{
RKObjectMapping * entityMapping = [RKObjectMapping mappingForClass:[Shop class]];
[entityMapping addAttributeMappingsFromDictionary:@{
@"@ID" : @"_id",
@"@Title" : @"title"
}];
//RKEntityMapping * shopMapping = [RKEntityMapping mappingForClass: [Shop class]];
//[entityMapping addRelationshipMappingWithSourceKeyPath:@"Shop" mapping:entityMapping];
[entityMapping addPropertyMapping:
[RKRelationshipMapping relationshipMappingFromKeyPath:@"Shop"
toKeyPath:@"Shop"
withMapping:entityMapping]];
return entityMapping;
}
@end
@implementation Shops
+ (RKObjectMapping *)jsonMapping
{
RKObjectMapping * entityMapping = [RKObjectMapping mappingForClass:[Shops class]];
[entityMapping addPropertyMapping:
[RKRelationshipMapping relationshipMappingFromKeyPath:@"Shop"
toKeyPath:@"Shop"
withMapping:[Shop jsonMapping]]];
return entityMapping;
}
@end
当我在Xcode模拟器中运行应用程序时,我发现它已成功调用服务器,并且已返回上述JSON。已创建LLSResponse对象,ErrorStatus对象和Events对象。但是,Shops对象没有。所以Shops / Shop映射存在问题,但我无法看到它。当我检查对象时,没有填充它们。我不知道这是一个单独的问题还是商店问题的结果。
商店实际上是API返回的无关数据。有没有办法跳过它?如果根本没有映射会发生什么;这是一个错误吗?
编辑2:文字被删除。
由于