使用 Restkit RKParams 发送 JSON 请求
我需要向 REST 服务发送 JSON 请求。我正在使用 Restkit RKParams 发送请求。
目前它的工作原理如下:
[params setValue:@"-46.566393" forParam:@"checkin[lng]"];
[params setValue:@"-23.541576" forParam:@"checkin[lat]"];
发送:
{
"checkin":
{
"lng":"-26.566393",
"lat":"-63.541576"
}
}
现在我想形成这样的 JSON 数据(还有更多项目):
{
"checkin":
{
"lng":"-26.566393",
"lat":"-63.541576",
"votes":
[
{"vote_id":28},
{"vote_id":11}
]
}
}
我将如何设置参数以按需要工作?有可能这样做吗?
I need to send a JSON request to a REST service. I'm using Restkit RKParams to send a request.
Currently it works as follows:
[params setValue:@"-46.566393" forParam:@"checkin[lng]"];
[params setValue:@"-23.541576" forParam:@"checkin[lat]"];
Send:
{
"checkin":
{
"lng":"-26.566393",
"lat":"-63.541576"
}
}
Now I want to form JSON data like this (with few more items):
{
"checkin":
{
"lng":"-26.566393",
"lat":"-63.541576",
"votes":
[
{"vote_id":28},
{"vote_id":11}
]
}
}
How would I set the params to work as desired? It is possible to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
RestKit 确实处理嵌套模型,但看起来它并没有直接在 RKParams 中执行此操作。我会看看其他一些课程来完成您想做的事情。 键值映射 看起来它会做你想要的。
或者如果你想破解它,
也许可行。但没有任何承诺。
RestKit does handle nested models, but it looks like it doesn't do that directly in RKParams. I would look at some of the other classes to do what you're trying to do. Key-value mapping looks like it will do what you want.
Or if you want to hack it,
might just work. No promises, though.