我在使用我的应用程序实现RestKit / CoreData时遇到了一些问题。使用RKTwitterCoreData示例应用程序并将其指向我的json feed的Web服务,我得到了生成的tableview:
到目前为止遇到的问题:
这是我的applicationDidFinishLaunchingWithOptions:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Initialize RestKit
RKObjectManager* objectManager = [RKObjectManager managerWithBaseURLString:@"http://mywebservice.com"];
// Enable automatic network activity indicator management
objectManager.client.requestQueue.showsNetworkActivityIndicatorWhenBusy = YES;
NSString *databaseName = @"RKTwitterData.sqlite";
objectManager.objectStore = [RKManagedObjectStore objectStoreWithStoreFilename:databaseName usingSeedDatabaseName:nil managedObjectModel:nil delegate:self];
RKManagedObjectMapping* statusMapping = [RKManagedObjectMapping mappingForClass:[Order class] inManagedObjectStore:objectManager.objectStore];
statusMapping.primaryKeyAttribute = @"orderID";
[statusMapping mapKeyPath:@"id" toAttribute:@"orderID"];
[statusMapping mapAttributes:@"created_at", nil];
// Register our mappings with the provider
[objectManager.mappingProvider setObjectMapping:orderMapping forResourcePathPattern:@"/orders"];
// Create Window and View Controllers
RKTwitterViewController* viewController = [[[RKTwitterViewController alloc] initWithNibName:nil bundle:nil] autorelease];
UINavigationController* controller = [[UINavigationController alloc] initWithRootViewController:viewController];
UIWindow* window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[window addSubview:controller.view];
[window makeKeyAndVisible];
return YES;
}
json结果为/ orders:
处理此问题的任何建议?谢谢!
答案 0 :(得分:0)
卫生署!原因是因为twitter API不符合键值编码。一旦我改变了:
[objectManager.mappingProvider setObjectMapping:orderMapping forResourcePathPattern:@"/orders"];
使用:
[objectManager.mappingProvider setObjectMapping:orderMapping forKeyPath:@"orders"];
又恢复了工作!
谢谢并希望它有所帮助。