Send JSON request with Restkit RKParams

僤鯓⒐⒋嵵緔 提交于 2020-01-04 02:16:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!