这JSON字符串必须发送:
{
"dashboard": "compact",
"theme": "dark",
"show_side_bar": "yes"
}
使用这种格式GET方法(因为服务器与此PHP代码检索数据的REST API $_GET["setting"]
与AFHTTPRequestOperationManager
,使得等效URL变为:
http://www.examplesite.com/api/change_setting?setting={ "dashboard" : "compact", "theme" : "dark", "show_side_bar" : "yes" }
当我创建NSDictionary
的参数AFHTTPRequestOperationManager
的GET:parameters:success:failure:
这更增加了参数字典本身这样的URL关键参数 :
{
"setting": {
"dashboard": "compact",
"theme": "dark",
"show_side_bar": "yes"
}
}
总之仅 JSON字符串必须在设置参数不象在一个JSON字符串设置的对象进行封装。
编辑:下面的代码:
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
}];