RestKit - POST 响应对象映射
我的 RESTful web 服务(Rails)上有方法“getBuses”。该方法需要返回 我的 JSON 格式的公交车列表。但是,当我发送“/getBuses.json”请求时,我 需要发送
params = [NSDictionary
dictionaryWithObjectsAndKeys: @"2011-08-16", @"datum", @"TRUE",
@"fromSerbia", nil];
我正在发布参数,因为我需要过滤响应(仅针对特定 特定日期的游览)。 然后,我期待这样的响应:
{
"buses" : [ {
"bus_number" : "1",
"created_at" : "2011-08-15T23:07:52Z",
"id" : 1,
"lat" : 44.815,
"long" : 20.4665,
"model" : "Setra",
"registar_number" : "123456",
"seats" : 50,
"tour_id" : 1,
"updated_at" : "2011-08-15T23:07:52Z"
}, {
"bus_number" : "2",
"created_at" : "2011-08-15T23:07:52Z",
"id" : 2,
"lat" : 44.812,
"long" : 20.465,
"model" : "Mercedes",
"registar_number" : "2234",
"seats" : 60,
"tour_id" : 1,
"updated_at" : "2011-08-15T23:07:52Z"
} ]
}
我只需要带有 Bus 对象的 NSArray 。 你能给我代码示例如何发出此请求并使用 RestKit 进行对象映射吗?
I have method "getBuses" on my RESTful webservice (Rails). That method needs to return
me list of buses in JSON. But, when I sending request for "/getBuses.json" I
need to send
params = [NSDictionary
dictionaryWithObjectsAndKeys: @"2011-08-16", @"datum", @"TRUE",
@"fromSerbia", nil];
I'm posting params because I need filtered response (just for specific
tour on specific date).
Then, I expecting response like this:
{
"buses" : [ {
"bus_number" : "1",
"created_at" : "2011-08-15T23:07:52Z",
"id" : 1,
"lat" : 44.815,
"long" : 20.4665,
"model" : "Setra",
"registar_number" : "123456",
"seats" : 50,
"tour_id" : 1,
"updated_at" : "2011-08-15T23:07:52Z"
}, {
"bus_number" : "2",
"created_at" : "2011-08-15T23:07:52Z",
"id" : 2,
"lat" : 44.812,
"long" : 20.465,
"model" : "Mercedes",
"registar_number" : "2234",
"seats" : 60,
"tour_id" : 1,
"updated_at" : "2011-08-15T23:07:52Z"
} ]
}
I just need NSArray with Bus objects.
Can you give me code example how to make this request and make object mapping with RestKit?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如我在 IRC 频道中告诉您的,在 RKClient 实例中,您可以使用以下方法:
(NSURL *)URLForResourcePath:(NSString *)resourcePath queryParams:(NSDictionary *)queryParams
所以您应该这样做:
该方法构建一个有效的使用资源路径和您作为参数提供的参数的 URL。然后您需要使用 NSURL 对象的absoluteString 将其设置回来。希望这有帮助!
As I told you in the IRC Channel, in your RKClient instance you can use this method:
(NSURL *)URLForResourcePath:(NSString *)resourcePath queryParams:(NSDictionary *)queryParams
So you should do it like this:
That method builds a valid URL using the resourcePath and the parameters you give as parameter. And then you need to set it back using the absoluteString of the NSURL object. Hope this helps!