我希望在post请求中将字典作为afnetworking中的param但是我无法发送nsdictionary php结束我无法解码。 这是我的代码
NSMutableDictionary *dict_hashtags=[[NSMutableDictionary alloc]init];
AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:[NSURL URLWithString:[BASE_URL stringByAppendingString:ADD_POST]]];
AFJSONRequestSerializer *requestSerializer = [AFJSONRequestSerializer serializer];
[requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[requestSerializer setValue:api_key forHTTPHeaderField:@"Authorization"];
manager.requestSerializer = requestSerializer;
AFJSONResponseSerializer *responseSerializer = [AFJSONResponseSerializer serializer];
responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html", nil];
manager.responseSerializer = responseSerializer;
NSString *font_size = [NSString stringWithFormat:@"%f", textSize];
if([self.txt_hashtags.text length]>0)
{
NSLog(@"lenght is greater");
dict_hashtags=[self getHashTags:self.txt_hashtags.text];
}
NSLog(@"HASHTAGS ARE %@",dict_hashtags);
NSDictionary *parameters = @{@"title": postTitle, @"details" :postDescription,@"location":address,@"font_size":font_size,@"font_family":fontName,@"font_color":color_name,@"is_album":isAlbum,@"hash_tag":dict_hashtags};
NSLog(@"PARAMS ARE %@",parameters);
AFHTTPRequestOperation *op = [manager POST:[BASE_URL stringByAppendingString:ADD_POST] parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData)
{
//do not put image inside parameters dictionary as I did, but append it!
if(userImageData!=nil)
{
[formData appendPartWithFileData:userImageData name:@"album_image" fileName:@"image0" mimeType:@"image/jpeg"];
}
}
success:^(AFHTTPRequestOperation *operation, id responseObject)
{
}
failure:^(AFHTTPRequestOperation *operation, NSError *error)
{
[self activityIndicator:@"hide"];
NSLog(@"Error: %@ ***** %@", operation.responseString, error);
UIAlertView *AlbumAlert =[[UIAlertView alloc]initWithTitle:@"Warning" message:@"Album could not added.Try again" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[AlbumAlert show];
}];
[op start];
我的参数如下:
PARAMS ARE {
details = "Gggghh\n";
"font_color" = black;
"font_family" = "Helvetica-Nue";
"font_size" = "18.000000";
"hash_tag" = {
"hash_tags" = (
ghygg
);
};
"is_album" = no;
location = "";
title = ggg;
}