Question

I'm sending a dictionary 'childDetails' which has a dictionary (rewards) as one of its objects.

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager POST:url parameters:childDetails constructingBodyWithBlock:^(id<AFMultipartFormData> formData) 

This "rewards" dictionary has two keys "name" and "value" which looks like {@"name",@"Reward 1",@"value",@"10"}.

when this gets posted to the server, the server receives it as follows;

 Array
(
    [group_id] => 5
    [name] => John Doe
    [rewards] => Array
        (
            [0] => Array
                (
                    [name] => Sample reward 2
                )

            [1] => Array
                (
                    [value] => 50
                )

            [2] => Array
                (
                    [name] => Sample Reward 1
                )

            [3] => Array
                (
                    [value] => 10
                )

        )

    [tasks] => Array
        (
            [0] => Array
                (
                    [title] => Default task one
                )

            [1] => Array
                (
                    [title] => Default task two
                )

            [2] => Array
                (
                    [title] => Default task five
                )

        )

    [token] => 5332884c2bc8c5
)

Any Idea how to fix this?

Any help is much appreciated.

Thanks in advance

Was it helpful?

Solution 2

I found out that inorder to get it to work, you have to reformat your dictionary. In my case I had to change it as;

NSDictionary *parameters = @{
    @"rewards": @[
        {@"reward name",@"reward value"},
        {@"reward name",@"reward value"}
    ]
};;

OTHER TIPS

I think the "parameters: param of POST: only accepts key/value pairs. Are you sure you don't have to serialize manually your objects first ? Can you print the content of "childDetails" please ?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top