带有“/"的 RKRoute因为参数不起作用 [英] RKRoute with "/" as parameter doesn't work

查看:54
本文介绍了带有“/"的 RKRoute因为参数不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置 RKRoute 以使用 RestKit 从 Dropbox API 获取文件夹内容.

I'm trying to set up a RKRoute to get folder contents from the Dropbox API using RestKit.

获取内容的网址是https://api.dropbox.com/1/metadata/dropbox/.

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

So I set up the response and route like this:

// 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

但是在 [RKPathMathermatchesPath:tokenizeQueryStrings:parsedArguments: 中匹配路径失败,因为在那里检查斜线的数量是这样的:RKNumberOfSlashesInString(self.patternString) == RKNumberOfSlashesInString(self.rootPath)

But then matching of the path fails in [RKPathMather matchesPath:tokenizeQueryStrings:parsedArguments: because there the number of slashes are checked like this: RKNumberOfSlashesInString(self.patternString) == RKNumberOfSlashesInString(self.rootPath)

当我注释掉这个检查时,映射有效,但我确定在其他一些情况下需要它.

The mapping works, when I comment out this checking, but I'm sure it's needed in some other cases.

推荐答案

正确的方法是使用 2 个不同的响应描述符和路由.斜线对于让 RestKit 正确区分不同的 URL、路径和模式很重要.您可以使用相同的映射,因此它只是"另外几行配置.

The correct approach is to use 2 different response descriptors and routes. The slashes are important to allow RestKit to properly differentiate between different URLs, paths and patterns. You can use the same mapping so it's 'just' another couple of lines of configuration.

这篇关于带有“/"的 RKRoute因为参数不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆