【发布时间】:2015-09-15 19:13:17
【问题描述】:
我不知道这是一个错误还是我做得不对。
这篇文章看起来非常接近为我解决它,但没有:AFNetworking posts JSON arrays as multiple single-entry dictionaries
我正在尝试发送带有图像的 multipart/form-data POST 并将字典(包含字典数组)传递给“参数”以作为 JSON 发送。
字典:
NSDictionary *parameters = @{@"photos" : @[@{@"photoID":@"0", @"imageURL":@"0", @"imageName":@"0"},
@{@"photoID":@"1", @"imageURL":@"1", @"imageName":@"1"},
@{@"photoID":@"2", @"imageURL":@"2", @"imageName":@"2"}]};
请求:
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
[manager POST:@"myURL" parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileData:imageData name:@"image" fileName:@"image" mimeType:@"image/png"];
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Success: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
图像正在发送和接收正常,但是在服务器上接收到的 JSON 如下所示:
{
photos = (
{
imageName = 0;
},
{
imageURL = 0;
},
{
photoID = 0;
},
{
imageName = 1;
},
{
imageURL = 1;
},
{
photoID = 1;
},
{
imageName = 2;
},
{
imageURL = 2;
},
{
photoID = 2;
}
);
}
...多个单项字典的数组 :(
代替:
{
photos = (
{
imageName = 0;
imageURL = 0;
photoID = 0;
},
{
imageName = 1;
imageURL = 1;
photoID = 1;
},
{
imageName = 2;
imageURL = 2;
photoID = 2;
}
);
}
任何帮助都会很棒,谢谢!
【问题讨论】:
标签: php ios objective-c afnetworking afnetworking-2