美文网首页
Alamofire post JSON数据

Alamofire post JSON数据

作者: xcmy | 来源:发表于2016-12-08 12:21 被阅读0次

1. swift3.0发送参数为json的post请求

let parms = ["name":"liu","age":3,"height":170]

Alamofire.request("http://xxxxx", method: .post, 
                                  parameters:parms,
                                  encoding: JSONEncoding.default,
                                  headers:[:])
            .validate().responseJSON { (response) in
            if response.result.isSuccess
            {
                print("请求成功:\n\(response.result.value!)")
            }else
            {
                print("\(response.debugDescription)") 
            }
        }

如上所示,加入encoding: JSONEncoding.default即可

2. 前端发送参数为json的post请求

$.ajax({
            type:'post',
            datatype:"json", 
            url: 'http://xxx',
            data:$.toJSON(parms),
            success:function(data){
                console.log(data)
            }
        })

加入$.toJSON()即可

相关文章

网友评论

      本文标题:Alamofire post JSON数据

      本文链接:https://www.haomeiwen.com/subject/vtfsmttx.html