AFNetworking GET parameters with a JSON string (NSDictionary) contained in the URL key parameter

This JSON string should be sent:

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

in the REST API using the GET method in this format (since the server retrieves the data using this PHP code $_GET["setting"]) s AFHTTPRequestOperationManager, so the equivalent URL will look like this:

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

When I create the NSDictionaryparameters in AFHTTPRequestOperationManager GET:parameters:success:failure:, which adds the url key parameter to the parameter dictionary, like this:

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

In short, only the JSON string should be encapsulated in the NOT parameter as an object in JSON.

Edit: Here is the 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
     }];
+4
source share
2

:

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
     }];
+5

php GET To request, POST,

0

All Articles