
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,NSError *error,ID JsON) {}];[operation start]; 在Node.Js后端,打印出正文显示:
{ customers: [ '1','blah@blah.com' ] } 预期印刷品应为:
{ customers: [{ facebook:'1',email:'blah@blah.com' }] } 我究竟做错了什么?
解决方法 来自AFNetworking维基:总结How do I send JsON parameters in my request?
If you’re using AFhttpClIEnt,set the parameterEnCoding property to
AFJsONParameterEnCoding. Any method on that http clIEnt with a
parameters argument will Now encode the passed object into a JsON
string and set the http body and Content-Type header appropriately.Otherwise,you can do this manually by adding the header Content-Type: application/Json,and setting the body of your request to a JsON string.
以上是内存溢出为你收集整理的ios – 嵌套的NSDictionary和NSArray,AFNetworking无法正常工作全部内容,希望文章能够帮你解决ios – 嵌套的NSDictionary和NSArray,AFNetworking无法正常工作所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)