以“/”作为参数的RKRoute不起作用

我试图设置RKRoute从Dropbox API使用RestKit获取文件夹内容。

获取内容的URL是https://api.dropbox.com/1/metadata/dropbox/<path>

所以我设置了这样的响应和路由:

 // objectManagers baseURL is @"https://api.dropbox.com/1/" RKResponseDescriptor *rootResponse = [RKResponseDescriptor responseDescriptorWithMapping:dynamicMapping pathPattern:@"metadata/dropbox:path" keyPath:nil statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]; [objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[DropboxFolder class] pathPattern:@"metadata/dropbox:path" method:RKRequestMethodGET]]; // dropboxFolder.path is @"/" for root // dropboxFolder.path is @"/Images" for the "Images"-folder contained in root 

但是,然后匹配的path失败[RKPathMather matchesPath:tokenizeQueryStrings:parsedArguments:因为那里检查斜杠的数量是这样的: RKNumberOfSlashesInString(self.patternString) == RKNumberOfSlashesInString(self.rootPath)

映射的工作,当我注释这个检查,但我相信这是在其他一些情况下需要。

正确的方法是使用2个不同的响应描述符和路由。 斜杠对于RestKit能够正确区分不同的URL,path和模式非常重要。 您可以使用相同的映射,因此它只是另外几行configuration。

我想我find了一个更清洁的解决scheme来解决我的问题:

我configuration我的响应描述符和路线是这样的:

 RKResponseDescriptor *rootResponse = [RKResponseDescriptor responseDescriptorWithMapping:dynamicMapping pathPattern:@"metadata/dropbox/:path" keyPath:nil statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]; RKRoute *route = [RKRoute routeWithClass:[DropboxFolder class] pathPattern:@"metadata/dropbox/:path" method:RKRequestMethodGET]; route.shouldEscapePath = YES; [objectManager.router.routeSet addRoute:route]; 

现在可以使用1个响应描述符和1个路由。 我不知道这是否适用于其他使用path的API,但它与Dropbox。 (根目录的URL现在是https://api.dropbox.com/1/metadata/dropbox/%2F