我不知道這是一個錯誤還是我只是不正確。AFNetworking multipart/form-data POST發送不正確的JSON字典陣列
這個職位看起來如此接近解決它爲我,但沒有:AFNetworking posts JSON arrays as multiple single-entry dictionaries
我試圖與發送的圖像的multipart/form-data發佈和傳遞一個字典(其中包含數組字典)以'參數'作爲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;
}
);
}
任何幫助將是巨大的,謝謝!
謝謝,這很棒 –