objective c - AFNetworking GET parameters with JSON (NSDictionary) string contained in URL key parameter -


this json string has sent:

{ "dashboard": "compact", "theme": "dark", "show_side_bar": "yes" } 

to rest api using get method in format (since server retrieves data php code $_get["setting"]) afhttprequestoperationmanager, such equivalent url becomes:

http://www.examplesite.com/api/change_setting?setting={ "dashboard" : "compact", "theme" : "dark", "show_side_bar" : "yes" }

when create nsdictionary of parameters in afhttprequestoperationmanager's get:parameters:success:failure: adds url key parameter parameter dictionary this:

{   "setting": {     "dashboard": "compact",     "theme": "dark",     "show_side_bar": "yes"   } } 

in short only json string must encapsulated in setting parameter not object of setting in json string.

edit: here's code:

afhttprequestoperationmanager *manager = [afhttprequestoperationmanager manager]; nsdictionary *parameters = @{                              ksettingdashboard: @"compact",                              ksettingtheme: @"dark",                              ksettingshowsidebar: @"yes"                              };  [manager get:kurlchangesetting   parameters:[nsdictionary dictionarywithobject:parameters forkey:@"setting"]      success:^(afhttprequestoperation *operation, id responseobject) {          // code      } failure:^(afhttprequestoperation *operation, nserror *error) {          /// code      }]; 

try this:

nsdata *jsondata = [nsjsonserialization datawithjsonobject:parameters options:0 error:nil]; nsstring *parametersstring = [[nsstring alloc] initwithdata:jsondata encoding:nsutf8stringencoding];  [manager get:kurlchangesetting   parameters:@{@"setting" : parametersstring}      success:^(afhttprequestoperation *operation, id responseobject) {          // code      } failure:^(afhttprequestoperation *operation, nserror *error) {          /// code      }]; 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -