问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/6528834/send-json-request-with-restkit-rkparams