所以我想從我的鐵軌搶JSON信息應用與RestKit的Rails 3.2.8 + RestKit - 映射不KVC
我的代碼這樣做,是像這樣:
應用代表
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//Initialise RestKit
NSURL *URL = [NSURL URLWithString:@"https://myapp.dev"];
AFHTTPClient* client = [[AFHTTPClient alloc] initWithBaseURL:URL];
//Enable Activity Indicator Spinner
[AFNetworkActivityIndicatorManager sharedManager].enabled = YES;
[client setDefaultHeader:@"Accept" value:RKMIMETypeJSON];
RKObjectManager *objectManager = [[RKObjectManager alloc] initWithHTTPClient:client];
RKObjectMapping *eventMapping = [RKObjectMapping mappingForClass:[Info class]];
[infoMapping addAttributeMappingsFromDictionary:@{
@"sample":@"sample",
@"sample_1":@"sample_1"
}];
RKResponseDescriptor *infoDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:infoMapping
pathPattern:@"/info"
keyPath:nil
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[objectManager addResponseDescriptor:infoDescriptor];
}
查看文件
- (void)loadInfo
{
RKObjectManager *objectManager = [RKObjectManager sharedManager];
[objectManager getObjectsAtPath:@"/info"
parameters:nil
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSArray *info = [mappingResult array];
NSLog(@"Loaded info: %@", info);
_info = info;
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error getting into"
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
NSLog(@"Hit error: %@", error);
}];
}
問題是。在日誌輸出上,RestKit告訴我它成功映射了所有的東西。但後來當我嘗試用兩種方法來查看對象登錄視圖文件,並使用po
調試與我得到以下
374 Finished performing object mapping. Results: {
"<null>" = "<Info: 0xa291b30>";
}
我無法查看對象,並使用斷點它顯示爲:
我一直在掙扎這幾天,我不知道什麼嘗試。任何幫助將不勝感激
這適用於單個對象。但是,說你的休息api(在這種情況下來自鐵路)返回多個對象。你如何將它們全部映射到一個對象中? – samdunne
你的迴應是什麼? –
儘管它有內容,它仍然是(null) – samdunne