【发布时间】:2015-10-11 13:03:58
【问题描述】:
我正在使用一个 POST 网络服务,它采用这样的参数
jsonObj = {
"id" : 0,
"platform" : 1,
"method" : "Home"
}
那么如何在参数中发送它我正在使用AFNetworking来消费webservice。
我的代码
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
[manager.requestSerializer setValue:ContentType forHTTPHeaderField:@"Content-Type"];
NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:0],@"id",[NSNumber numberWithInt:1],@"platform",API_HomeProductList,@"method", nil];
NSDictionary *param =[NSDictionary dictionaryWithObjectsAndKeys:dic,@"jsonObj", nil];
[manager POST:APIMainURL parameters:param success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSMutableDictionary *json = [[NSMutableDictionary alloc]initWithDictionary:[NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil]]; //
NSLog(@"JSON: %@",json);
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}];
当我通过 AFNetworking 将其转换为 Json 后看到我的参数时,它变为有效的 json
{
"jsonObj" = {
"id" : 0,
"platform" : 1,
"method" : "Home"
}
}
但是我得到了一些错误,因为我的网络服务占用了
jsonObj = {
"id" : 0,
"platform" : 1,
"method" : "Home"
}
作为参数
所以请建议我如何发送
jsonObj = {
"id" : 0,
"platform" : 1,
"method" : "Home"
}
在参数中。
【问题讨论】:
-
看到这个链接可能对你有帮助stackoverflow.com/questions/21344580/…
标签: ios objective-c iphone json afnetworking