当前位置: 移动技术网 > IT编程>移动开发>IOS > IOS用AFN发送字符串形式的Json数据给服务器实例

IOS用AFN发送字符串形式的Json数据给服务器实例

2019年07月24日  | 移动技术网IT编程  | 我要评论

医生手术后默哀,兄弟之生死同盟下载,购得乐

每个人遇到后台的需求不一样,我只能写出自己目前遇到的需求和做法,我的后台是需要一个json的key,对应一个字符串类型的字典,后台要求的是带双引号和冒号的字典,所以就拼接了一下

afhttpsessionmanager *manager = [afhttpsessionmanager manager];
  // 发送post请求
//  manager.responseserializer = [afjsonresponseserializer serializer];
  manager.responseserializer = [afjsonresponseserializer serializer];
  manager.responseserializer.acceptablecontenttypes = [nsset setwithobject:@"text/html"];
  //
  manager.requestserializer=[afhttprequestserializer serializer];
  nsdictionary *json = [nsdictionary dictionary];
   nsstring *str = [nsstring stringwithformat:@"{\"city\":\"%@\",\"country\":\"%@\",\"headimgurl\":\"%@\",\"language\":\"%@\",\"openid\":\"%@\",\"province\":\"%@\",\"sex\":%@,\"unionid\":\"%@\",\"username\":\"%@\"}",self.userinfodict[@"city"],self.userinfodict[@"country"],self.userinfodict[@"headimgurl"],self.userinfodict[@"language"],self.userinfodict[@"openid"],self.userinfodict[@"province"],self.userinfodict[@"sex"],self.userinfodict[@"unionid"],self.userinfodict[@"nickname"]];
  json = @{
//      @"city":self.userinfodict[@"city"],
//      @"country":self.userinfodict[@"country"],
//      @"headimgurl":self.userinfodict[@"headimgurl"],
//      @"language":self.userinfodict[@"language"],
//      @"openid":self.userinfodict[@"openid"],
//      @"province":self.userinfodict[@"province"],
//      @"sex":self.userinfodict[@"sex"],
//      @"unionid":self.userinfodict[@"unionid"],
//      @"username":self.userinfodict[@"nickname"],
      @"json":str,
//      @"json":@"json"
      
          };
  nslog(@"post调试%@",json);
  nsstring *urlstr = @"http://10.62.16.247:8080/loginservlet.bmh";
  
  [manager post:urlstr parameters:json progress:^(nsprogress * _nonnull uploadprogress) {
    
  } success:^(nsurlsessiondatatask * _nonnull task, id _nullable responseobject) {
    nsstring *str = responseobject;
    nslog(@"post回调====%@",str);
    nslog(@"post成功");
  } failure:^(nsurlsessiondatatask * _nullable task, nserror * _nonnull error) {
    nslog(@"post失败");
  }];

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网