我正在嘗試爲以下JSON數據創建映射。JSON的RestKit對象映射
{
"Calls": [
{
"id": "18",
"parent_id": "0",
"status": "completed",
},
{
"id": "19",
"parent_id": "0",
"status": "completed",
},
}
我正在使用以下方法來映射和處理來自委託的響應。當我運行這個時,didLoadObjects方法從未被命中並且沒有記錄。另外,我確信URL是正確的,URL返回我上面發佈的JSON。
- (void)viewDidLoad
{
[super viewDidLoad];
RKLogConfigureByName("RestKit/*", RKLogLevelTrace);
RKObjectMapping *callMapping = [RKObjectMapping mappingForClass:[YCMDCall class]];
[callMapping mapKeyPath:@"id" toAttribute:@"call_id"];
[callMapping mapKeyPath:@"parent_id" toAttribute:@"parent_id"];
[callMapping mapKeyPath:@"status" toAttribute:@"status"];
RKObjectManager *manager = [[RKObjectManager sharedManager] managerWithBaseURL:@"http://MYBASEURL/"];
[manager.mappingProvider setMapping:callMapping forKeyPath:@"Calls"];
[manager loadObjectsAtResourcePath:@"RESTOFURL" objectMapping:callMapping delegate:self];
}
- (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)objects
{
NSLog(@"Load collection of Articles: %@", objects);
}
- (void)objectLoader:(RKObjectLoader *)objectLoader didFailWithError:(NSError *)error
{
NSLog(@"Oh no! Error: %@", [error localizedDescription]);
}
此外,如果任何人都可以提供一個例子或指向我在正確的方向將這些結果導入到TableViewController。預先感謝您的幫助。
@interface YCMDCall : NSObject
@property (nonatomic, retain) NSString* call_id;
@property (nonatomic, retain) NSNumber* parent_id;
@property (nonatomic, retain) NSString* status;
@end
@implementation YCMDCall
@synthesize call_id;
@synthesize parent_id;
@synthesize status;
@end
嗨,你解決了你的問題嗎? – Beber 2012-04-03 09:02:45
是的,大多隻是忽略了一些簡單的東西。 – 2012-04-08 08:25:25