AFNetworking 不想在 JSON 请求中将 BOOL 值表示为真/假。尝试了@YES,NSNumber 但没有机会,它转换为 0 或 1。
NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
[data setValue:@YES forKey:@"favorite"];
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
[params setObject:data forKey:@"data"];
然后将此参数字典提供给 AfNetworking 3
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
AFJSONRequestSerializer *serializer = [AFJSONRequestSerializer serializer];
[serializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[serializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
manager.requestSerializer = serializer;
[manager POST:@"HTTPS://JSON URL" parameters:params progress:^(NSProgress *uploadProgress) {
} success:^(NSURLSessionDataTask * task, id responseObject) {
//SUCCESS
} failure:^(NSURLSessionDataTask *task, NSError *error) {
//FAILED REQUEST
}];