Ios 嵌套词典&;带有AFN网络的NSArray无法正常工作

Ios 嵌套词典&;带有AFN网络的NSArray无法正常工作,ios,json,node.js,nsurlrequest,afnetworking,Ios,Json,Node.js,Nsurlrequest,Afnetworking,在Node.JS后端,打印正文显示: NSDictionary *customerDictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"blah@blah.com", @"email", @"1", @"facebook", nil]; NSArray *customerArray = [NSArray arrayWithObjects:customerDictionary, nil]; NSDictionary *parameter

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

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];
预期的印刷品应为:

{ customers: [ '1', 'blah@blah.com' ] }

我做错了什么?

来自AFNetworking wiki:

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

如果使用的是AFHTTPClient,请将parameterEncoding属性设置为 AFJSONParameterEncoding。HTTP客户端上具有 parameters参数现在将传递的对象编码为JSON 字符串并适当设置HTTP正文和内容类型标头

否则,您可以通过添加标题内容类型手动执行此操作: application/json,并将请求主体设置为json 绳子


可能是你打印错了?看起来这是服务器上的问题,而不是IOS。您最好也在服务器端提供代码。在发送请求之前记录帖子正文,看看是否正确。打印输出是req.body的Node.JS中的一个简单console.Log。这是原始打印出来的。不管怎么说,phix23的回答对我有帮助。天哪,不管我读了多少次维基,我不知怎么跳过了这一部分。这是为了我!谢谢(直到11小时才能颁发赏金)。
{ customers: [{ facebook:'1', email:'blah@blah.com' }] }