问题描述
我需要将JSON请求发送到REST服务.我正在使用Restkit RKParams发送请求.
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]"];
发送:
{
"checkin":
{
"lng":"-26.566393",
"lat":"-63.541576"
}
}
现在,我想像这样形成JSON数据(还有其他几项):
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?
推荐答案
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,
[RKParams setValue:@"[{\"vote_id\":28},{\"vote_id\":11}]" forParam:@"checkin[votes]"]
可能会工作.不过,没有承诺.
might just work. No promises, though.
这篇关于使用Restkit RKParams发送JSON请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!