使用RESTKit将url参数映射到对象 [英] Map url parameters to objects using RESTKit

查看:140
本文介绍了使用RESTKit将url参数映射到对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法将URL中的参数映射到结果?



我有一个休息服务,用户可以通过其ID搜索某些内容。路径为 search /:id
结果包含名称和其他属性,但不包含ID。



<我可以这样做:

  NSArray * array = mappingResult.array; 
for(Item * item in array){
[item setId:itemID];
}

但我希望有更好的方式......



感谢任何提示

Xean

解决方案

你想要使用您在响应描述符中指定的路径模式。然后,您希望在映射期间使用路由( RKRoute )和元数据。元数据包括一个路由部分,可以访问从URL路径中提取的参数。



元数据的一些信息这里(文档有点缺乏)。



在您想要使用的映射中:

  @ metadata.routing.parameters.id 

作为映射源键路径。






要使路由工作,您需要添加到对象管理器的路径:

  [manager.router.routeSet addRoute:... 

然后你需要以一种意味着使用该路由的方式发出请求,例如 getObjectsAtPathForRouteNamed:object:参数:成功:失败:


is there a way to map the parameters in an URL to the results?

I got a rest service where the user can search something by its ID. The path is search/:id The results contains the name and other properties but not the ID.

I could do something like this:

NSArray *array = mappingResult.array;
for (Item *item in array) {
        [item setId:itemID];
}

but I hope there is a nicer way...

Thanks for any hints
Xean

解决方案

You want to use the path pattern you specify in your response descriptor. Then you want to use routing (RKRoute) and metadata during your mapping. The metadata includes a routing section which gives access to the parameters extracted from the URL path.

Some info on metadata here (the docs are a little lacking).

In your mapping you want to use:

@metadata.routing.parameters.id

As the mapping source key path.


To make routing work you need to add the route to your object manager:

[manager.router.routeSet addRoute:...

And then you need to make the request in a way that means the route is used, like getObjectsAtPathForRouteNamed:object:parameters:success:failure:.

这篇关于使用RESTKit将url参数映射到对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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