I am trying to post a JSON message which contains an array to my server. However the server is unable to identify the elements in the array. After inspecting the issue I have come across what I believe is the problem.
AFNetworking code:
AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] initWithBaseURL:[NSURL URLWithString:kServiceBaseUrl]];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
[manager PUT:@"/api/createRubaway"
parameters:myDictionary
success:^(NSURLSessionDataTask *task, NSDictionary *responseObject)
{/* stuff */}
failure:^(NSURLSessionDataTask *task, NSError *error)
{/* stuff */}
];
LLDB print out of 'myDictionary':
{
description = description;
title = title;
transitions = (
{
idx = 0;
resource = {
data = testdata;
name = transition;
type = image;
};
threshold = "0.75";
type = rubaway;
},
{
idx = 1;
resource = {
data = testdata;
name = transition;
type = image;
};
threshold = "0.75";
type = rubaway;
}
);
}
After AFNetworking has serialized the request. If I print out the HTTPBody from the NSMutableRequest, this is what it is sending (this is what is being sent to my server):
description=description&title=title&transitions[][idx]=0&
transitions[][resource][data]=testdata&
transitions[][resource][name]=transition&
transitions[][resource][type]=image&
transitions[][threshold]=0.75&
transitions[][type]=rubaway&transitions[][idx]=1&
transitions[][resource][data]=testdata&
transitions[][resource][name]=transition&
transitions[][resource][type]=image&transitions[][threshold]=0.75&
transitions[][type]=rubaway
Is the above formatting correct. As my server (Node.js - BodyParser) I believe is expecting it in this format https://stackoverflow.com/a/18402556/623750
Is there a way to change the formatting of the JSON serializer?. Alternatively is there a way to configure BodyParser to accept the above formatting?
Thanks, Ryan