嵌套的NSDictionary和NSArray,AFNetworking无法正常工作

nin*_*eer 4 json nsurlrequest node.js ios afnetworking

NSDictionary *customerDictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"blah@blah.com", @"email", @"1", @"facebook", nil];
NSArray *customerArray = [NSArray arrayWithObjects:customerDictionary, nil];
NSDictionary *parameters = [NSDictionary dictionaryWithObjectsAndKeys:customerArray, @"customers", nil];
NSURLRequest *request = [sharedHTTPClient requestWithMethod:@"POST" path:@"/api/upload" parameters:parameters];
AFJSONRequestOperation *operation =
    [AFJSONRequestOperation JSONRequestOperationWithRequest:request
                                                    success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {}
                                                    failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {}];
[operation start];
Run Code Online (Sandbox Code Playgroud)

在Node.JS后端,打印出正文显示:

{ customers: [ '1', 'blah@blah.com' ] }
Run Code Online (Sandbox Code Playgroud)

预期印刷品应为:

{ customers: [{ facebook:'1', email:'blah@blah.com' }] }
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

Fel*_*lix 7

来自AFNetworking维基:

如何在我的请求中发送JSON参数?

如果您正在使用AFHTTPClient,请将parameterEncoding属性设置为AFJSONParameterEncoding.具有参数参数的HTTP客户端上的任何方法现在将传递的对象编码为JSON字符串,并相应地设置HTTP正文和Content-Type标头.

否则,您可以通过添加标题Content-Type:application/json,并将请求的主体设置为JSON字符串来手动执行此操作.